Rectangles
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
#include <iostream>
#include <iomanip>
using namespace std;
double cc(double a,double b)
{
if(a<b) return a;
else return b;
}
double bb(double a,double b)
{
if(a<b) return b;
else return a;
}
int main()
{
double x1,x2,x3,x4;
double y1,y2,y3,y4;
double a,b,c,d,t;
while(cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4)
{
if(x1>x2) {t=x1;x1=x2;x2=t;}
if(y1>y2) {t=y1;y1=y2;y2=t;}
if(x3>x4) {t=x3;x3=x4;x4=t;}
if(y3>y4) {t=y3;y3=y4;y4=t;}
a=bb(x1,x3);
b=cc(x2,x4);
c=bb(y1,y3);
d=cc(y2,y4);
cout<<setiosflags(ios::fixed)<<setprecision(2);
cout<<((a>b||c>d)?0:(b-a)*(d-c))<<endl;
}
return 0;
}
Rectangles的更多相关文章
- 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 ...
- HDU 2056 Rectangles
Rectangles Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Number of Rectangles in a Grid
Project Euler 85: Investigating the number of rectangles in a rectangular grid Number of Rectangles ...
随机推荐
- 获取oracle sql语句中绑定变量值的方法
在诊断 sql的性能问题时,我们有时候须要获取其绑定变量的实际值,然后将此实际值带入到sql语句其中,用原来的sql构成select语句(带where条件),实际的运行一下,看一下选择性怎样. 本文就 ...
- javascript如何判断访问网页的设备及是否支持触屏功能
var system ={}; var p = navigator.platform; system.win = p.indexOf("Win") == 0; system.mac ...
- T-SQL事务
事务 订火车票的时候,下一个订单,这个订单中,包含多个购买信息,要么全部执行,要么全部不执行,合作事务就是来处理这种模型的一种机制. --关键字:transaction 或 tran 简写形式 --开 ...
- js callback函数
A callback is a function that is passed as an argument to another function and is executed after its ...
- 反射消除String类对象的不可变特性
大家都知道,在JAVA中字符串一旦声明就不可改变,如果尝试修改字符串的内容,将会重新实例化一个新的字符串对象,这也是为了安全性和效率. 由于字符串在程序之中被大量使用,所以JAVA引入了一个字符串常量 ...
- 生成HFile文件后倒入数据出现Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.filter.Filter
数据导入的时候出现: at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclar ...
- android中viewPager实现的屏幕左右切换(入门篇)
大多数的APP都可以实现几个屏幕来回的切换, 首先新建两个Activity,内容随意,布局随意.接下来在MainActivity.xml: <RelativeLayout xmlns:andro ...
- Twitter License for Android
1.Apache Software Foundation Apache 软件基金会 2.Apache Thrift 跨平台传输数据,Thrift与其他传输方式的比较: xml与JSON相比体积太 ...
- Scala基础入门-1
首先需要Scala开发环境的搭建,网上自己找教程. 声明常量与变量 val foo = 0 // 常量 var bar = 0 // 变量 在Scala中,更加鼓励使用val来进行声明,也就是推荐使用 ...
- Android Activity之 setContentView()总结
从一开始hello world的第一个安卓应用开始,Activity 自动生成,布局自动生成,直接修改布局,在Activity中,findviewById()找到view,然后处理相应的业务逻辑即可, ...