hdu 2056 Rectangles

来源:互联网 发布:财务计算软件 编辑:程序博客网 时间:2024/05/18 03:50

Rectangles

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 19460    Accepted Submission(s): 6312


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.005.00 5.00 13.00 13.00 4.00 4.00 12.50 12.50
 

Sample Output
1.0056.25
 

Author
seeyou
 

Source
校庆杯Warm Up
 

Recommend
linle   |   We have carefully selected several similar problems for you:  2054 2057 2062 2060 2059 
给出两个矩形对角线的坐标,求这两个矩形重叠的面积
把这四个点从小到大排序,找出中间两个点即为重叠部分,注意不重叠时的情况
#include<stdio.h>#include<math.h>#include<string.h>#include<algorithm>using namespace std;int main(){    double x1,y1,x2,y2,a1,b1,a2,b2;    while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&a1,&b1,&a2,&b2)){        if(x1>x2)swap(x1,x2);if(y1>y2)swap(y1,y2);if(a1>a2)swap(a1,a2);if(b1>b2)swap(b1,b2);double ex=x1>a1?x1:a1;double ey=y1>b1?y1:b1;double tx=x2>a2?a2:x2;double ty=y2>b2?b2:y2; if(tx<ex||ty<ey)printf("0.00\n");elseprintf("%.2lf\n",(tx-ex)*(ty-ey));}return 0; } 


0 1
原创粉丝点击