码迷,mamicode.com
首页 > 其他好文 > 详细

5D - Rectangles

时间:2019-02-08 01:09:14      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:isp   case   没有   tput   positive   nts   智商   can   ted   

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

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

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

// 没考虑无相交区域
技术图片
 1 #include<stdio.h>
 2 int main()
 3 {
 4     double x1,y1, x2,y2, x3,y3, x4,y4, a,b, t;
 5     while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)!=EOF)
 6     {
 7         if(x1>x2)
 8         { t=x2; x2=x1; x1=t; }
 9         if(y1>y2)
10         { t=y2; y2=y1; y1=t; }
11         if(x3>x4)
12         { t=x4; x4=x3; x3=t; }
13         if(y3>y4)
14         { t=y4; y4=y3; y3=t; }
15         a=x1-x4>x3-x2?x1-x4:x3-x2;
16         b=y1-y4>y3-y2?y1-y4:y3-y2;
17         printf("%.2f\n", a*b);
18     }
19     return 0;
20 }
WA
// 还是错得离谱 感觉没有智商T^T
技术图片
 1 #include<stdio.h>
 2 int main()
 3 {
 4     double x1,y1, x2,y2, x3,y3, x4,y4, a,b, t;
 5     while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)!=EOF)
 6     {
 7         if(x1>x2)
 8         { t=x2; x2=x1; x1=t; }
 9         if(y1>y2)
10         { t=y2; y2=y1; y1=t; }
11         if(x3>x4)
12         { t=x4; x4=x3; x3=t; }
13         if(y3>y4)
14         { t=y4; y4=y3; y3=t; }
15         a=x1-x4>x3-x2?x1-x4:x3-x2;
16         b=y1-y4>y3-y2?y1-y4:y3-y2;
17         if(a>=0||b>=0) printf("0.00\n");
18         else printf("%.2f\n", a*b);
19     }
20     return 0;
21 }
WA*2
// 
技术图片
 1 #include<stdio.h>
 2 int main()
 3 {
 4     double x1,y1, x2,y2, x3,y3, x4,y4, a,b, t;
 5     while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4)!=EOF)
 6     {
 7         if(x1>x2)
 8         { t=x2; x2=x1; x1=t; }
 9         if(y1>y2)
10         { t=y2; y2=y1; y1=t; }
11         if(x3>x4)
12         { t=x4; x4=x3; x3=t; }
13         if(y3>y4)
14         { t=y4; y4=y3; y3=t; }
15         a=(x2<x4?x2:x4)-(x1>x3?x1:x3);
16         b=(y2<y4?y2:y4)-(y1>y3?y1:y3);
17         if(a<0||b<0) printf("0.00\n");
18         else printf("%.2f\n", a*b);
19     }
20     return 0;
21 }
AC

 

5D - Rectangles

标签:isp   case   没有   tput   positive   nts   智商   can   ted   

原文地址:https://www.cnblogs.com/goldenretriever/p/10355783.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!