HDOJ 2056 Rectangles
Problem Description
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
题目大意:求两个矩形相交的面积,矩形的边均平行于坐标轴。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
double[] x = new double[4];
double[] y = new double[4];
for(int i=0;i<x.length;i++){
x[i] = sc.nextDouble();
y[i] = sc.nextDouble();
}
if(x[1]<x[0]){
double temp=x[0];
x[0]=x[1];
x[1]=temp;
}
if(y[1]<y[0]){
double temp=y[0];
y[0]=y[1];
y[1]=temp;
}
if(x[3]<x[2]){
double temp=x[3];
x[3]=x[2];
x[2]=temp;
}
if(y[3]<y[2]){
double temp=y[3];
y[3]=y[2];
y[2]=temp;
}
double x1 = max(x[0],x[2]);
double y1 = max(y[0],y[2]);
double x2 = min(x[1],x[3]);
double y2 = min(y[1],y[3]);
if(x1>x2||y1>y2){
System.out.println("0.00");
continue;
}else{
System.out.printf("%.2f",(x2-x1)*(y2-y1));
System.out.println();
}
}
}
private static double min(double d, double e) {
if(d<e){
return d;
}
return e;
}
private static double max(double d, double e) {
if(d>e){
return d;
}
return e;
}
}
HDOJ 2056 Rectangles的更多相关文章
- HDOJ(2056)&HDOJ(1086)
Rectangles HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...
- HDU 2056 Rectangles
Rectangles Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 杭电oj2047-2049、2051-2053、2056、2058
2047 阿牛的EOF牛肉串 #include<stdio.h> int main(){ int n,i; _int64 s[]; while(~scanf("%d" ...
- 【HDOJ】1510 White Rectangles
这个题目很好,变形的题目也很多.简单DP. /* 1510 */ #include <cstdio> #include <cstring> #include <cstdl ...
- hdoj:2056
#include <iostream> #include <iomanip> #include <cstdlib> using namespace std; str ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ 1004 Let the Balloon Rise
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
随机推荐
- java 字符串转int
//字符转整形 String aa = "23"; //int bb = Integer.parseInt(aa);//两种方式都是可以的 int bb = new Integer ...
- postgresql sql修改表,表字段
1.更改表名 alter table 表名 rename to 新表名 2.更改字段名 alter table 表名 rename 字段名 to 新字段名 3.增加列 ALTER TABLE ud_w ...
- VS2010调试时候未响应
这几天使用vs2010,调试时候经常未响应,等了半天才缓过来,严重影响心情,决定解决这个问题. 搜寻一番,试着关闭VS,重新设置了vs2010的环境(在vs2010命令提示符下,执行devenv.ex ...
- html 5的localstorag
随着我们硬件技术的发展,浏览器本身的功能也愈发的完善,从之前的cookie到现在的本地缓存机制,再到web storage,在之前html4 的时候使用cookie具有一些明显的局限,如大小限制,co ...
- java 计算器SWT/RAP(版本3)键盘鼠标兼容
java 计算器SWT/RAP(版本3)键盘鼠标兼容,之前版本也对,但存在线程失效问题,当多人访问时,就容易线程失效,一直犯得一个错误就是一直用static变量和static方法, 之前加了什么js界 ...
- 【POJ3237】【树链剖分】Tree
Description You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edg ...
- Java多线程:Semaphore
Semaphore为并发包中提供用于控制某资源同时可以被几个线程访问的类 实例代码: // 允许2个线程同时访问 final Semaphore semaphore = new Semaphore(2 ...
- C宏系统缺陷
这两天稍稍看了一下boost的preprocessor库,发觉boost那帮疯子竟然利用各种奇技淫巧定义出各种数据类型和结构,还在上面定义出加减乘除等等各种运算,在快速浏览的过程中,还瞄到了很眼熟的各 ...
- [转载]python os.path模块
os.path模块主要用于文件的属性获取,在编程中经常用到,以下是该模块的几种常用方法.更多的方法可以去查看官方文档:http://docs.python.org/library/os.path.ht ...
- 【随记】VS异常:HRESULT: 0x80070057 (E_INVALIDARG)) 解决方案
今天公司突然断电后,来电重启VS,调试WebService时报错: 未能加载文件或程序集 “XXX” 或它的某一个依赖项.系统找不到指定的文件. 说明: 执行当前 Web 请求期间,出现未处理的异常 ...