POJ 1177 Picture(掃描線求周長)
與求面積並的差不多,但是這個與掃描的方向相同的情況不太好處理,如果掃描線離散化兩次掃兩遍其實也可以解決這個問題,但是這樣無論在時間還是空間上稍微就有點浪費了啊。這裡因為我是離散x坐標的所以對於平行於y軸的方向上的統計比較難統計。處理的方法是:標記區間左邊的斷點,和右邊的斷點,求出這個區間一共有多少個斷點。就可以統計出平行於y軸的長度了。這裡合並的時候需要判斷右邊的左區間和左邊的右區間是否相同,如果相同的話,說明他們連接到了一起,要減去多加的。
Picture
Time Limit: 2000MS
Memory Limit: 10000K
Total Submissions: 10300
Accepted: 5462
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 cZ喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcnJlc3BvbmRpbmcgYm91bmRhcnkgaXMgdGhlIHdob2xlIHNldCBvZiBsaW5lIHNlZ21lbnRzIGRyYXduIGluIEZpZ3VyZSAyLiA8YnI+CjxjZW50ZXI+PGltZyBzcmM9"http://www.2cto.com/uploadfile/Collfiles/20140809/20140809090654208.jpg" alt="\">
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.
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
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include