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 delete input与delete all input
oracle官方文档提示:If you had specified DELETE INPUT rather than DELETE ALL INPUT, then RMAN would have on ...
- 计算(a/b)%c
如果b与c互素,则(a/b)%c=a*b^(phi(c)-1)%c 如果b与c不互素,则(a/b)%c=(a%bc)/b 对于b与c互素和不互素都有(a/b)%c=(a%bc)/b成立
- case in esac ` for in do done ` while true / false
case in esac ` for in do done ` while true / false ` if {} fi
- memcached 内存管理 分析(转)
Memcached是一个高效的分布式内存cache,了解memcached的内存管理机制,便于我们理解memcached,让我们可以针对我们数据特点进行调优,让其更好的为我所用.这里简单谈一下我对me ...
- Google Map 根据坐标 获取地址信息
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.X ...
- sublime text 2中Windows下编写的脚本在Linux平台上运行遇到字符问题
今天在windows下的sublime text 2下写了个脚本,上传到ubuntu服务器中执行后提示: -bash: /usr/bin/python: /usr/bin/python^M: bad ...
- Android 相对布局常用属性
Android 布局属性详解 RelativeLayout用到的一些重要的属性: 第一类:属性值为true或false android:layout_centerHrizontal 水平居中 ...
- IScroll5+在ios、android点击(click)事件不兼容解决方法
Bug描述: ios.android4.4+下不能触发click事件. Bug解决: 调用iscroll插件,增加配置参数:click:true/false click的值是要根据移动终端设备进行判断 ...
- AJAX+cURL+SimpleXMLElement处理数据
curl_xml.html: <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- PHP中的数组方法及访问方法总结
一.数组操作的基本函数 数组的键名和值 array_values($arr);获得数组的值 array_keys($arr);获得数组的键名 array_flip($arr);数组中的值与键名互换(如 ...