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 ...
随机推荐
- Apple Swift学习资料汇总
今年的苹果开发者大会(WWDC)上,公布了ios8的几个新特性,其中包括引入了群聊功能,支持第三方输入法等功能.但更让开发者感兴趣的莫过于Swift语言的发布了. Swift是apple自创的一门转为 ...
- SpringMVC中采用简洁的配置实现文件上传
文件上传我们一般会有两种策略,一种是通过IO流上传,还有一种是通过表单上传,其实这两种在客户端实现起来都是很简单的,在服务端处理会略有差别,个人感觉IO上传代码简单,但是也有很多硬伤,还是表单上传更合 ...
- c#简单缓存使用,添加和修改
private void SetCache(string CacheKey, object objObject, DateTime dt) { System.Web.Caching.Cache obj ...
- c++数组操作
一.数组定义和初始化 : 一维数组初始化: : 标准方式一: ]; // value[i]的值不定,没有初始化 : 标准方式二: ] = {,}; // value[0]和value[1]的值分别为1 ...
- linux下socket编程-TCP
网络字节序 发送主机通常将发送缓冲区中的数据按内存地址从低到高的顺序发出,接收主机把从网络上接到的字节依次保存在接收缓冲区中,也是按内存地址从低到高的顺序保存,因此,网络数据流的地址应这样规定:先发出 ...
- php-mysql 问题笔记一——在命令行中可以执行的sql语句,无法从php页面页面执行!
我的情况: 1.由于外键较多,插入数据时,提前关闭外键(SET FOREIGN_KEY_CHECKS=0). 2.所使用的sql语句中,有外键绑定到其他表中,所以无法从php页面插入. 原因分析: S ...
- vb combobox 用法问题总结
问题一 combobox 通过type类型,如下代码,通过选取name名称(改变combobox的名称)得到 其Id Type User id As Integer userName As Strin ...
- 用U盘装win7/XP系统的操作
现在上网本越来越流行了,但是上网本是没有光驱的,那如何给上网本装系统就成了一个难题,其实不仅仅不带光驱的笔记本用户愁怎么装系统,那些没有光驱的台式机用户也愁.为了给这类用户提供方便,笔者今天以上网本装 ...
- FirewallD 详解
在CentOS7开始,默认是没有iptables的,而是使用了firewall防火墙.与时俱进,简单的整理了一下firewall的使用方法.关于详细的介绍参考官网,就不搬字了.这个网站有中文选项.可以 ...
- 杭电oj1062 Text Reverse
Tips:使用一个临时数组c[1000] ,将输入的数据一边复制一边处理,碰到空格时就将前面的字符反向输出即可 #include<stdio.h> #include<string.h ...