HDU2056(rectangles)
Rectangles
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 19299 Accepted Submission(s): 6255
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
Author
seeyou
Source
Recommend
linle | We have carefully selected several similar problems for you: 20572058206220602059
Statistic | Submit | Discuss | Note
这道题乍一看挺复杂,但是是有技巧的。只需要将4个横坐标和4个纵坐标排序然后就可简化成一种很容易计算的形式。还要注意首先要排除没有交叉部分的情况。
#include<stdio.h>
#include<algorithm>
using namespace std; int main()
{
double x[], y[];
while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x[], &y[], &x[], &y[], &x[], &y[], &x[], &y[])) {
double minx1 = min(x[], x[]), maxx1 = max(x[], x[]), minx2 = min(x[], x[]), maxx2 = max(x[], x[]);
double miny1 = min(y[], y[]), maxy1 = max(y[], y[]), miny2 = min(y[], y[]), maxy2 = max(y[], y[]);
if(minx1 >= maxx2 || maxx1 <= minx2 || maxy1 <= miny2 || miny1 >= maxy2) printf("%.2lf\n", );
else {
sort(x, x + );
sort(y, y + );
printf("%.2lf\n", (x[] - x[]) * (y[] - y[]));
}
}
}
HDU2056(rectangles)的更多相关文章
- HDU100题简要题解(2050~2059)
HDU2050 折线分割平面 题目链接 Problem Description 我们看到过很多直线分割平面的题目,今天的这个题目稍微有些变化,我们要求的是n条折线分割平面的最大数目.比如,一条折线可以 ...
- poj-1314 Finding Rectangles
题目地址: http://poj.org/problem?id=1314 题意: 给出一串的点,有些点可以构成正方形,请按照字符排序输出. 因为这道题的用处很大, 最近接触的cv 中的Rectangl ...
- [ACM_暴力][ACM_几何] ZOJ 1426 Counting Rectangles (水平竖直线段组成的矩形个数,暴力)
Description We are given a figure consisting of only horizontal and vertical line segments. Our goal ...
- codeforces 713B B. Searching Rectangles(二分)
题目链接: B. Searching Rectangles time limit per test 1 second memory limit per test 256 megabytes input ...
- White Rectangles[HDU1510]
White Rectangles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Java基础之在窗口中绘图——绘制直线和矩形(Sketcher 2 drawing lines and rectangles)
控制台程序. import javax.swing.JComponent; import java.util.*; import java.awt.*; import java.awt.geom.*; ...
- Counting Rectangles
Counting Rectangles Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1043 Accepted: 546 De ...
- UVA 10574 - Counting Rectangles 计数
Given n points on the XY plane, count how many regular rectangles are formed. A rectangle is regular ...
- Project Euler 85 :Counting rectangles 数长方形
Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 co ...
随机推荐
- 使用日期工具类:DateUtil
利用java开发,避免不了String.Date转换,前一天.后一天等问题.给出一个工具类,仅供学习交流. import java.text.DateFormat; import java.text. ...
- yii2 控制器里 action 大小写组合造成的路由问题
yii1中, 若存在如下控制器 class BindController extends CController { public function actionGetMobilePhone () { ...
- Python自动化之5种session类型
Django中默认支持Session,其内部提供了5种类型的Session供开发者使用: 数据库(默认) 缓存 文件 缓存+数据库 加密cookie 1.数据库Session Django默认支持Se ...
- Python之路,Day26-----暂无正在更新中
Python之路,Day26-----暂无正在更新中
- asp.net服务器控件防止多次提交问题
用户可能点击多次提交按钮.这样,导致向数据库中插入了多条相同的记录. 好像这2个方法都是针对的服务器控件! //方法一:在提交时调用一段客户端的代码. function a() { document. ...
- 获取Html中所有img的src
/// <summary> /// 获取所有Img中的Src /// </summary> /// <param name="htmlText"> ...
- CRT detected that the application wrote to memory after end of heap buffer.
很多人的解释都不一样, 我碰到的问题是,开辟的内存空间小于操作的内存空间.也就是说,我free的内存越界了. 这是我开辟链表结构体内存的代码: PNODE Create() { int len; / ...
- 安装php时,make步骤报错make: *** [ext/gd/gd.lo] Error 1
安装PHP时,make步骤报错make: *** [ext/gd/gd.lo] Error 1 /usr/local/src/LAMP+memcahed+catci/php-5.4.0/ext/gd/ ...
- iOS开发之字典数据建立模型步骤
1. 在控制器属性的(questions)set方法中完成字典转模型的操作 - (NSArray *)questions { if (nil == _questions) { //1.加载plist文 ...
- POJ 2010 Moo University - Financial Aid( 优先队列+二分查找)
POJ 2010 Moo University - Financial Aid 题目大意,从C头申请读书的牛中选出N头,这N头牛的需要的额外学费之和不能超过F,并且要使得这N头牛的中位数最大.若不存在 ...