hdu-2056-Rectangles
来源:互联网 发布:cloudzoom.js 编辑:程序博客网 时间:2024/06/05 19:06
Rectangles
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 25081 Accepted Submission(s): 8163
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
题意:
给出俩个矩形的顶点(对角线上的)。也就是说一个矩形,你知道俩个顶点,这俩个点在一条对角线上。那么求给出的俩个矩形的面积。
解题思路:
俩个矩形,有俩种情况,一:相交,二:不相交。感觉是废话。
不相交有俩种情况,如图,那么给x,y坐标从大到小排序,如果排序后前俩个横坐标是一个矩形的,或者纵坐标前俩个是一个矩形,那么他们肯定不相交。想想为什么?
可以看出重合的部分就是排序后中间的俩个数据。那么求面积就简单了。
# include <cstdio># include <algorithm>using namespace std;struct node{ int id; double num;};bool cmp(node a,node b){ return a.num < b.num;}int main(){ node x[6],y[6]; while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x[0].num,&y[0].num,&x[1].num,&y[1].num,&x[2].num,&y[2].num,&x[3].num,&y[3].num) != EOF) { x[0].id = x[1].id = y[0].id = y[1].id = 1; x[3].id = x[2].id = y[3].id = y[2].id = 2; sort(x,x+4,cmp); sort(y,y+4,cmp); if(x[1].id == x[0].id || y[1].id == y[0].id) { printf("0.00\n"); continue; } printf("%.2lf\n",(x[2].num-x[1].num)*(y[2].num-y[1].num)); } return 0;}
- hdu 2056 Rectangles
- HDU 2056 Rectangles
- hdu 2056 Rectangles
- HDU 2056 Rectangles
- HDU 2056 rectangles
- HDU - 2056 Rectangles
- HDU 2056 Rectangles
- HDU 2056 Rectangles
- HDU 2056 Rectangles
- hdu 2056 Rectangles
- hdu 2056 Rectangles
- hdu 2056 Rectangles
- HDU 2056 Rectangles
- hdu 2056 Rectangles
- hdu-2056-Rectangles
- HDU 2056 Rectangles
- hdu 2056 Rectangles
- hdu 2056 -- Rectangles (矩形重合)
- EditText-RecyclerView
- PaddlePaddle学习笔记:识别数字
- 创建缩略图
- 解决Web项目因访问URL与Tomcat服务器文件夹相同导致404页面的问题
- 类和对象
- hdu-2056-Rectangles
- Dubbox 构建Restful服务
- python3常用快捷键——将在学习中不断更新
- jdk 源码分析(6)java BitSet结构
- HDU4648 Magic Pen 6 签到
- [转载自知乎——有哪些令人拍案叫绝的算法?] [侵必付] 关于位运算
- 【PAT】【Advanced Level】1037. Magic Coupon (25)
- 其他对象——math
- 背包问题*