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 ...
随机推荐
- 浅谈Android架构之MVP,MVVM
概述 MVP(Model-View-Presenter)是传统MVC(Model-View-Controller)在Android开发上的一种变种.进化模式.主要用来隔离UI.UI逻辑和业务逻辑.数据 ...
- xUtils3源码分析(一):view的绑定
概述 xUtils3是国人开发的一款功能丰富的Android快速开发框架,值得研究下.zip包下载:[ZIP]xutils主要分以下几个模块 视图绑定模块 网络请求模块 数据库模块 图片加载模块 我们 ...
- 不用jquery等框架实现ajax无刷新登录
<script type="text/javascript"> window.onload = function () { document.getElementByI ...
- dns-prefetch—DNS预解析技术
今天在看一个网站的源代码时 发现了 <link rel="dns-prefetch" href="//static.tuweia.cn/"> 对dn ...
- c-指针的指针
概述: 贴上一个'经典C语言程序设计100例'的第77个程序 #include <stdio.h> int main(void) { char *s[]={"man", ...
- Deep Learning学习随记(一)稀疏自编码器
最近开始看Deep Learning,随手记点,方便以后查看. 主要参考资料是Stanford 教授 Andrew Ng 的 Deep Learning 教程讲义:http://deeplearnin ...
- 集成支付宝后出现LaunchServices: ERROR: There is no registered handler for URL scheme alipay
原因如下: There's no problem with your implementation. All those warnings mean is the apps which each UR ...
- 在浏览器运行 java applet时遇到的一些问题及其解决方法
运行 java applet时提示:您的安全设置已阻止本地应用程序运行,如何解决?如下图所示 这时候通过设置java的安全级别就可以了. 控制面板->程序->Java->安全 将安全 ...
- cocos2d-x 实现沙子特效
效果图. 说明. 标题取的不好, 原因是我也不知道这效果应该叫什么. 大概效果是这样的, 随着鼠标按下并且移动, 所到之处所有磁铁都将扩散. 就好比鼠标是一个圆形区域去排挤在场的磁铁. 话不多说, 直 ...
- Java学习----你可以告诉对象该怎么做(方法中传参)
对象根据参数传递来的条件执行相应的功能. package org.demo.app2; public class App2 { public void print(String msg, int nu ...