Algorithm 版 (精华区)
发信人: Lerry (想不开·撞树), 信区: Algorithm
标 题: Picture
发信站: 哈工大紫丁香 (2002年03月29日13:58:23 星期五), 站内信件
Picture
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.
Task
Write a program to calculate the perimeter.
An example with 7 rectangles is shown in Figure 1.
Figure 1. A set of 7 rectangles
The corresponding boundary is the whole set of line segments drawn in Figure
2.
Figure 2. The boundary of the set of rectangles
The vertices of all rectangles have integer coordinates.
Input Data
The first line of the file PICTURE.IN contains the number of rectangles past
ed on the wall. In each of the subsequent lines, one can find the integer co
ordinates of the lower left vertex and the upper right vertex of each rectan
gle. The values of those coordinates are given as ordered pairs consisting o
f an x-coordinate followed by a y-coordinate.
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
This corresponds to the example of Figure 1.
Output Data
The file PICTURE.OUT must contain a single line with a non-negative integer
which corresponds to the perimeter for the input rectangles.
Sample Output
228
This is the contents of the output file for the example above.
Constraints
0 <= number of rectangles < 5000
All coordinates are in the range [-10000,10000] and any existing rectangle h
as a positive area.
The numeric value of the result may need a 32-bit signed representation.
--
不在乎天长地久,就怕你从来没有!
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 天外飞仙]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.203毫秒