- 问题描述
Mr.Cai is a peasant who owns some field,but due to his neglect,he earned little this year.Now autumn gradually away
from us,it is time to hand in taxs again,there are many exorbitant taxes and levies.After knowing Mr.Cai's poor condition ,
the landlord named "Zhou Ba Pi" said:"It's fine,just give me your field as hypothecate,since you must work on it to earn
money for me ,I won't take them all,I'll set a rule to show how will I take apart these field".
The rule is described as follow:give you a rectangle,means Mr.Cai's field,then give you another rectangle,if this two rectangles overlaped,Zhou will take this part away,so your task is to calculate the area of overlaped part.To make it easier,we confirm that every side is vertical or horizontal.![NOJ——[1234] Mr.Cais Field - 深海灬孤独 - Alex](http://acm.nbut.edu.cn/res/image/20121012/20121012192753_78537.bmp)
- 输入
- There are multiple test cases.Every case include 8 real numbers,each with two decimal point,a1,b1,a2,b2,a3,b3,a4 b4,first rectangle is (a1,b1) - (a2,b2),another is(a3,b3) - (a4,b4).
Look at Sample input,it's explain is like the picture shown above. - 输出
- Each case output the area of overlaped part in a single line,and keep two decimal point too.
- 样例输入
1.00 6.00 3.00 4.00 2.00 5.00 4.00 2.00 -1.00 -1.00 1.00 1.00 2.00 2.00 3.00 3.00
- 样例输出
1.00 0.00
- 提示
无
- 来源
Mr.Cai
![NOJ——[1234] Mr.Cais Field - 深海灬孤独 - Alex NOJ——[1234] Mr.Cais Field - 深海灬孤独 - Alex](http://img0.ph.126.net/rDzumTqVRAadfVwyg6P2uw==/886646176738832802.png)
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
double x1,x2,y1,y2,x3,x4,y3,y4;
while(~scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2))
{
scanf("%lf%lf%lf%lf",&x3,&y3,&x4,&y4);
if(x1>x2)
swap(x1,x2);
if(y1>y2)
swap(y1,y2);
if(x3>x4)
swap(x3,x4);
if(y3>y4)
swap(y3,y4);
double lx=max(x1,x3);
double rx=min(x2,x4);
double ly=min(y4,y2);
double ry=max(y1,y3);
if(lx > rx || ly < ry )
printf("0.00\n");
else
printf("%.2f\n",(rx-lx)*(ly-ry));
}
return 0;
}
本文介绍如何通过编程计算两个矩形之间的相交面积,包括输入解析、边界处理及输出格式化。
3万+

被折叠的 条评论
为什么被折叠?



