题目描述代码实现
题目描述
给你两个矩形的左上角和右下角的坐标点(x11,y11)和(x12,y12)以及(x21,y21)和(x22,y22)
求它们相交的面积。
代码实现
#include<iostream
>
#include<cstdio
>
#include<cmath
>
using namespace std;
int main(){
pair<int, int
> p1, p2, p3, p4;
while(cin
>> p1
->first
>> p1
->second
>> p2
->first
>> p2
->second
>> p3
-> first
>> p3
->second
>> p4
->first
>> p4
->second) {
double maxx1
= max(p1
->first, p2
->first), minx1
=min(p1
->first, p2
->first), maxy1
=max(p1
->second, p2
->second), miny1
=min(p1
->second, p2
->second);
double maxx2
= max(p3
->first, p4
->first),minx2
= min(p3
->first, p4
->first), maxy2
= max(p3
->second, p4
->second),miny2
= min(p3
->second, p4
->second);
if(minx2
>= maxx1
|| minx1
>= maxx2
|| miny2
>= maxy1
|| maxy2
<= miny1){
cout
<<"0.00"<<endl;
}
else{
double xx
= max(minx1,minx2), yy
= max(miny1,miny2);
double x
= min(maxx1,maxx2), y
= min(maxy1,maxy2);
printf(
"%.2f\n",(abs(x
-xx)
*abs(y
-yy)));
}
}
return 0;
}
参考链接:http://blog.csdn.net/jdoun/article/details/50808355#
转载请注明原文地址: https://ju.6miu.com/read-18296.html