我是靠谱客的博主 喜悦大船,最近开发中收集的这篇文章主要介绍HDOJ1828(Picture )Picture ,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Picture

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 134    Accepted Submission(s): 78


Problem Description
A number of rectangular posters, photographs and other pictures of the same shape are pasted on a wall. Their sides are all vertical or horizontal. Each rectangle can be partially or totally covered by the others. The length of the boundary of the union of all rectangles is called the perimeter.

Write a program to calculate the perimeter. An example with 7 rectangles is shown in Figure 1.



The corresponding boundary is the whole set of line segments drawn in Figure 2.



The vertices of all rectangles have integer coordinates.
 

Input
Your program is to read from standard input. The first line contains the number of rectangles pasted on the wall. In each of the subsequent lines, one can find the integer coordinates of the lower left vertex and the upper right vertex of each rectangle. The values of those coordinates are given as ordered pairs consisting of an x-coordinate followed by a y-coordinate.

0 <= number of rectangles < 5000
All coordinates are in the range [-10000,10000] and any existing rectangle has a positive area.

Please process to the end of file.
 

Output
Your program is to write to standard output. The output must contain a single line with a non-negative integer which corresponds to the perimeter for the input rectangles.
 

Sample Input
7
-15 0 5 10
-5 8 20 25
15 -4 24 14
0 -6 16 4
2 15 10 22
30 10 36 20
34 0 40 16
 

Sample Output
228

 

//1282707 2009-04-18 08:34:47 Accepted 1828 15MS 668K 1915 B C++ Xredman 
#include <iostream>
#include 
<algorithm>
using namespace std;

const int M = 5003;
const int N = 10002;

typedef 
struct
expandedblockstart.gifcontractedblock.gif
{
    
int s,e,pp;//三点确定一条直线位置
    
// 1 stand for the start line
    
// 0 stand for the end line
    int status;
}
Line;

bool cmp(Line a, Line b)
expandedblockstart.gifcontractedblock.gif
{
    
if(a.pp == b.pp)
expandedsubblockstart.gifcontractedsubblock.gif    
{
        
return a.status > b.status;
    }

    
else
        
return a.pp < b.pp;
}


Line Lx[
2 * M], Ly[2 * M];
int n, ans;
int *level;

void init()
expandedblockstart.gifcontractedblock.gif
{
    
int x1, y1, x2, y2;
    
int kk = 0;
    
for(int i = 0; i < n; i++)
expandedsubblockstart.gifcontractedsubblock.gif    
{
        scanf(
"%d%d%d%d"&x1, &y1, &x2, &y2);

expandedsubblockstart.gifcontractedsubblock.gif        
/**////初始化始边/////

        Lx[kk].s 
= x1; Lx[kk].e = x2; Lx[kk].pp = y1; Lx[kk].status = 1;
        Ly[kk].s 
= y1; Ly[kk].e = y2; Ly[kk].pp = x1; Ly[kk].status = 1;
        kk
++;

expandedsubblockstart.gifcontractedsubblock.gif        
/**/////初始化终边///

        Lx[kk].s 
= x1; Lx[kk].e = x2; Lx[kk].pp = y2; Lx[kk].status = 0;
        Ly[kk].s 
= y1; Ly[kk].e = y2; Ly[kk].pp = x2; Ly[kk].status = 0;
        kk
++;
    }

    n 
= kk;
    ans 
= 0;
    sort(Lx, Lx 
+ n, cmp);
    sort(Ly, Ly 
+ n, cmp);
}


void solve(Line * str)
expandedblockstart.gifcontractedblock.gif
{
    
int i, j;

expandedsubblockstart.gifcontractedsubblock.gif    
/**///对层次初始化///
    for(i = -10000; i <= 10000; i++)
        level[i] 
= 0;
    
for(i = 0; i < n; i++)
expandedsubblockstart.gifcontractedsubblock.gif    
{
        
if(str[i].status == 1)
expandedsubblockstart.gifcontractedsubblock.gif        
{//对始边做处理
            for(j = str[i].s ; j < str[i].e; j++)
expandedsubblockstart.gifcontractedsubblock.gif            
{
                level[j]
++;
expandedsubblockstart.gifcontractedsubblock.gif                
/**////始边由0 -> 1, 可以确定是边缘边//
                if(level[j] == 1)
                    ans
++;
            }

        }

        
else
expandedsubblockstart.gifcontractedsubblock.gif        
{
            
for(j = str[i].s ; j < str[i].e; j++)
expandedsubblockstart.gifcontractedsubblock.gif            
{//对终边做处理
                level[j]--;
expandedsubblockstart.gifcontractedsubblock.gif                
/**////终边由1 -> 0, 可以确定是边缘边//
                if(level[j] == 0)
                    ans
++;
            }

        }

    }

}


int main()
expandedblockstart.gifcontractedblock.gif
{
    
    level 
= new int[2 * N];
    level 
+= N;
    
while(cin>>n)
expandedsubblockstart.gifcontractedsubblock.gif    
{
        init();
        solve(Lx);
        solve(Ly);
        cout
<<ans<<endl;
    }

    
return 0;
}

 

转载于:https://www.cnblogs.com/Xredman/archive/2009/04/18/1438503.html

最后

以上就是喜悦大船为你收集整理的HDOJ1828(Picture )Picture 的全部内容,希望文章能够帮你解决HDOJ1828(Picture )Picture 所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(36)

评论列表共有 0 条评论

立即
投稿
返回
顶部