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的更多相关文章

  1. poj-1314 Finding Rectangles

    题目地址: http://poj.org/problem?id=1314 题意: 给出一串的点,有些点可以构成正方形,请按照字符排序输出. 因为这道题的用处很大, 最近接触的cv 中的Rectangl ...

  2. [ACM_暴力][ACM_几何] ZOJ 1426 Counting Rectangles (水平竖直线段组成的矩形个数,暴力)

    Description We are given a figure consisting of only horizontal and vertical line segments. Our goal ...

  3. codeforces 713B B. Searching Rectangles(二分)

    题目链接: B. Searching Rectangles time limit per test 1 second memory limit per test 256 megabytes input ...

  4. White Rectangles[HDU1510]

    White Rectangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. Java基础之在窗口中绘图——绘制直线和矩形(Sketcher 2 drawing lines and rectangles)

    控制台程序. import javax.swing.JComponent; import java.util.*; import java.awt.*; import java.awt.geom.*; ...

  6. Counting Rectangles

    Counting Rectangles Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1043 Accepted: 546 De ...

  7. UVA 10574 - Counting Rectangles 计数

    Given n points on the XY plane, count how many regular rectangles are formed. A rectangle is regular ...

  8. Project Euler 85 :Counting rectangles 数长方形

    Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 co ...

  9. HDU 2056 Rectangles

    Rectangles Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  10. Number of Rectangles in a Grid

    Project Euler 85: Investigating the number of rectangles in a rectangular grid Number of Rectangles ...

随机推荐

  1. 泛泰A900 刷4.4专用中文TWRP2.7.1.1版 支持自己主动识别手机版本号(全球首创)

    因本人手上的A900S已砖, 所以临时弄不了ROM了, 先上传之前已经弄好的刷4.4专用的新版TWRP recovery 2.7.1.1  这个版本号是我自己定义的,为差别之前公布的2.7.0.0版( ...

  2. [AS3]as3用ByteArray来对SWF文件编码加密实例参考

    [AS3]as3用ByteArray来对SWF文件编码加密实例参考,简单来说,就是将 swf 以 binary 的方式读入,并对 ByteArray 做些改变,再重新存成 swf 档.这个作业当然也可 ...

  3. 移动端WEB开发 代码片段

    WebApp是指基于Web的系统和应用,其作用是向广大的最终用户发布一组复杂的内容和功能(不明白说的是什么).其实Web APP就是一个针对Iphone.Android等智能手机优化后的web站点,它 ...

  4. Error in invoking target 'agent nmhs' of makefile

    安装Oracle11g报错:Error in invoking target 'agent nmhs' of makefile  解决方法:cd $ORACLE_HOME/sysman/libvi i ...

  5. 搭建MyBatis框架

    一.开发环境 1.JDK 1.6.0_22 2.MyEclipse 10.7.1 3.Oracle_10g_10.2.0.4 注:各软件版本不是必须的,正常任意版本都行,文件较大就不附上下载地址了,推 ...

  6. HTTP请求的基本概念 HTTP请求头和响应头的含义

    1,HTTP请求的基本概念    TCP/UPD/HTTP    *2,HTTP请求头和响应头的含义  请求头:  Accept: text/html,image/*(浏览器可以接收的类型)  Acc ...

  7. UVA 1614 - Hell on the Markets

    题意: 输入n个数,第i个数ai满足1≤ai≤i.对每个数添加符号,使和值为0. 分析: 排序后从最大的元素(假设为k)开始,凑出sum/2即可.用去掉了k的集合,一定可以凑出sum/2 - a[k] ...

  8. HTML——JavaScript简介

    一.简介: JavaScript是个脚本语言,需要有宿主文件,他的宿主文件是HTML文件. JavaScript 是属于 web 的语言,它适用于 PC.笔记本电脑.平板电脑和移动电话. JavaSc ...

  9. js中添加事件 attachEvent 与 addEventListener

    给元素添加事件时,使用js进行实现时产生了疑惑,有关事件浏览器兼容的问题,在此记录如下. <!DOCTYPE html> <html> <head> <met ...

  10. VIM设置-发现VIM的美

    今天在Linux上调代码,突然发现连高亮都没有.到网上找了找,发现一个大神的微博里有. 在此记录:http://www.cnblogs.com/ma6174/archive/2011/12/10/22 ...