On a paper that defines a Cartesian coordinate system, draw a rectangle (x1,y1) to (x2,y2) to color the area of the horizontal axis from X1 to x2, and the ordinate range from Y1 to Y2.
Gives an example of a two-rectangle drawing. The first rectangle is (a) to (4, 4), expressed in green and purple. The second rectangle is (2, 3) to (6, 5), expressed in blue and purple. In the figure, a total of 15 units of the area were painted color, wherein the purple portion was painted two times, but only once when calculating the area. In the actual coloring process, all the rectangles are painted in a uniform color, the picture shows that the different colors are for illustrative convenience only.
Give all the rectangles you want to draw, how many units of the total area are painted in color.
Input format
The first line of the input contains an integer n that represents the number of rectangles to draw.
The next n lines, 4 nonnegative integers per line, represent the horizontal and vertical coordinates of the lower-left corner of the rectangle to be drawn, and the horizontal and vertical coordinates of the upper-right corner.
Output format
Outputs an integer that indicates how many units of an area are painted.
Sample input
2
1 1 4 4
2 3 6 5
Sample output
15
Measuring use case size and conventions
1<=n<=100,0<= horizontal axis, ordinate <=100.
Not much to say, give the code:
1#include <iostream>2 using namespacestd;3 4 inta[401][401];5 6 voidMainvoid)7 {8 intN;9 intx0, y0, x1, y1;Ten intresult; One while(Cin >>N) A { -memset (A,0,401*401); -result =0; the for(intt =1; t <= N; t++) - { -Cin >> x0 >> y0 >> x1 >>Y1; - + for(inti = x0; I < X1; i++) - for(intj = y0; J < Y1; J + +) +A[I][J] =1; A } at for(inti =0; I <= -; i++) - for(intj =0; J <= -; J + +) - if(A[i][j]) -Result + =A[i][j]; -cout << Result <<Endl; - } in}
How many rectangles are covered