Rectangles
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 19110 Accepted Submission (s): 6187
Problem Descriptiongiven-rectangles and the coordinates of the points on the diagonals of each rectangle,you has to C Alculate the area of the intersected part of the rectangles. Its sides is parallel to OX and OY.
Inputinput the first line of input was 8 positive numbers which indicate the coordinates of four points that must being on EAC H Diagonal. The 8 numbers is x1,y1,x2,y2,x3,y3,x4,y4. That means the points on the first rectangle is (x1,y1), (x2,y2); the other and the points on the second rectangle is (x3,y 3), (X4,Y4).
Outputoutput for each case output, the area of their intersected part, a single line.accurate up to 2 decimal places.
Sample Input1.00 1.00 3.00 3.00 2.00 2.00 4.00 4.005.00 5.00 13.00 13.00 4.00 4.00 12.50 12.50
Sample Output1.0056.25 Parse: Adjust the coordinates to find the length and width of the repeating part, thus obtaining the area.
1#include <cstdio>2#include <algorithm>3 using namespacestd;4 5 DoubleX1,y1,x2,y2,x3,y3,x4,y4;6 Doubletmp;7 8 intMain ()9 {Ten while(~SCANF ("%LF%LF%LF%LF%LF%LF%LF%LF",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)) { One if(X1>X2) {//make (X1,Y1) the lower-left corner, (X2,Y2) the upper-right corner of the point ATMP =X1; -X1 =x2; -x2 =tmp; the } - if(y1>y2) { -TMP =Y1; -Y1 =Y2; +y2 =tmp; - } + if(x3>x4) {//make (X3,Y3) the lower-left corner, (X4,Y4) the upper-right corner of the point ATMP =X3; atx3 =x4; -x4 =tmp; - } - if(y3>y4) { -TMP =Y3; -Y3 =Y4; inY4 =tmp; - } to Doublelength = min (x2,x4)-Max (x1,x3); + Doublewidth = min (y2,y4)-Max (y1,y3); -printf"%.2f\n",length<0|| width<0?0: length*width); the } * return 0; $}
HDU 2056 Rectangles