Pro.ID10210 TitlePicture Title链接http://10.20.2.8/oj/exercise/problem?problem_id=10210 AC13 Submit46 Ratio28.26% 时间&空间限制描述A number, N ( 1 ≤ N < 5000 ), 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. Figure 1 shows an example with seven rectangles:
The corresponding boundary is the whole set of line segments drawn in Figure 2:
The vertices of all rectangles have integer coordinates. All coordinates are in the range [-10000, 10000] and any existing rectangle has a positive area. The numeric value of the result fits in a 32-bit signed representation. 输入Multiple test cases. For each case, Line 1: N, the number of rectangles pasted on the wall. Lines 2..N+1: 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. 输出Description A number, N ( 1 ≤ N < 5000 ), 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. Figure 1 shows an example with seven rectangles:
The corresponding boundary is the whole set of line segments drawn in Figure 2:
The vertices of all rectangles have integer coordinates. All coordinates are in the range [-10000, 10000] and any existing rectangle has a positive area. The numeric value of the result fits in a 32-bit signed representation. Input Multiple test cases. For each case, Line 1: N, the number of rectangles pasted on the wall. Lines 2..N+1: 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. Output For each case, output a single line with a non-negative integer which corresponds to the perimeter for the input rectangles. Sample Input 7 Sample Output 228 Source 样例输入7 样例输出228 作者 |