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. Basic Concepts of Block Media Recovery

    Basic Concepts of Block Media Recovery Whenever block corruption has been automatically detected, yo ...

  2. WCF通信过程

    无废话WCF入门教程二[WCF应用的通信过程] 一.概述 WCF能够建立一个跨平台的安全.可信赖.事务性的解决方案,是一个WebService,.Net Remoting,Enterprise Ser ...

  3. JAVASCRIPT——图片滑动效果

    点击按钮开始整体右移,移动至蓝色区域全部显示出来停止. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&qu ...

  4. HTML网页制作:[12]使用框架结构之frameset

    首先,我希望在你的目录下,有4个网页,各自显示不同的内容. 如图所示: 1.html显示“火影忍者” 2.html显示“英雄联盟” 3.html显示“嵌入式开发.网页开发.安卓开发” 4.html显示 ...

  5. Java面试题整理(题目内容非原创)

    面试题分类: 1.java 基础面试题 Java基础中对于io 中文件的读.写,util中的list map set这些要分清楚 还有线程.socket 都需要了解下 参考链接:http://blog ...

  6. HDU 1038 - Biker's Trip Odometer

    算一下路程和速度... #include <iostream> #include <cstdio> using namespace std; const double p=3. ...

  7. MySQL如何使用索引 较为详细的分析和例子

    在数据库表中,使用索引可以大大提高查询速度. 假如我们创建了一个 testIndex 表: CREATE TABLE testIndex(i_testID INT NOT NULL,vc_Name V ...

  8. css3之3D翻牌效果

      最近一直在学css3,发现他真的是越来越牛逼.现在的css3已经不在是以前的css了,它能做出的功能效果是我们没法想象的了.它可以实现flash,可以制作一些js能做出来的效果,还可以写出ps做出 ...

  9. Spring2.0集成Quartz1.5.2调度框架

    Quartz是个开放源码项目,提供了丰富的作业调度集.希望您在阅读完本文并看过代码演示后,可以把Quartz的基本特性应用到任何Java™应用程序中.现代的Web应用程序框架在范围和复杂性方面都有所发 ...

  10. 《彻底搞定C指针》文档整理

    一.变量存储 #include <stdio.h> int main(void) { ; printf(“%d\n”, i); printf(“%d\n”, &i); //十进制打 ...