Rectangles
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 20939 Accepted Submission(s): 6818
Problem Description
Given two rectangles and the coordinates of two points on the diagonals of each rectangle,you have to calculate the area of the intersected part of two rectangles. its sides are parallel to OX and OY .
Input
Input The first line of input is 8 positive numbers which indicate the coordinates of four points that must be on each diagonal.The 8 numbers are x1,y1,x2,y2,x3,y3,x4,y4.That means the two points on the first rectangle are(x1,y1),(x2,y2);the other two points on the second rectangle are (x3,y3),(x4,y4).
Output
Output For each case output the area of their intersected part in a single line.accurate up to 2 decimal places.
Sample Input
1.00 1.00 3.00 3.00 2.00 2.00 4.00 4.00 5.00 5.00 13.00 13.00 4.00 4.00 12.50 12.50
Sample Output
1.00 56.25题意大约就是给你对角线上的两个点(没说是主对角线还是副对角线),先统一对角线(主或副),我这里统一成主对角线,然后就可以拿这些进行就算了 基本上都是高中知识,代码付下:#include <stdio.h> int change(double a[]) { double tmp; if(a[0]>a[2]) { tmp=a[0]; a[0]=a[2]; a[2]=tmp; } if(a[1]<a[3]) { tmp=a[1]; a[1]=a[3]; a[3]=tmp; } if(a[4]>a[6]) { tmp=a[4]; a[4]=a[6]; a[6]=tmp; } if(a[5]<a[7]) { tmp=a[5]; a[5]=a[7]; a[7]=tmp; } return 0; } int main() { double a[8],b[4]; int i,j; while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7])) { change(a); b[0] = a[0] > a[4]?a[0]:a[4]; // x 0 b[1] = a[1] < a[5]?a[1]:a[5]; // y 0 b[2] = a[2] < a[6]?a[2]:a[6]; // x 1 b[3] = a[3] > a[7]?a[3]:a[7]; // y 1 if(b[2]-b[0]<0||b[1]-b[3]<0) { printf("0.00\n"); } else{ printf("%.2lf\n",(b[2]-b[0])*(b[1]-b[3])); } } return 0; }