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 ...
随机推荐
- 点击文字可以选中相应的checkbox
<html><head><title>中国站长天空-网页特效-表单特效-点击文字选中的复选框</title><meta http-equiv=&q ...
- 在oracle中怎么把一张表的数据插入到另一张表中
把table2表的数据插入到table1中 insert into table1 select * from table2
- 深入了解java集群技术
原文源自:http://blog.csdn.net/happyangelling/article/details/6413584 序言 越来越多的关键应用运行在J2EE(Java 2, Enterpr ...
- iOS菜鸟之苹果开发者账号的注册
大家一起来讨论讨论苹果开发者账号的注册(主要是以公司的开发者账号为例),前段时间公司要求注册开发者账号,于是我就特地看了看相关的帖子.这里简单给大家总结一下具体的流程. 首先你要登陆这个网址,进去之后 ...
- laravel5通过auth.attempt事件加入登陆验证码
<?php namespace WangDong\Http\Controllers\Auth; use Illuminate\Http\Exception\HttpResponseExcepti ...
- Struts2中使用execAndWait后,在 Action中调用getXXX()方法报告java.lang.NullPointerException异常的原因和解决方法
使用 Struts2 编写页面,遇到一个要长时间运行的接口,因此增加了一个execAndWait ,结果在 Action 中调用 getContext()的时候报告异常 ActionContext c ...
- swfupload上传文件问题
如果你的框架用到了struts2的话 可能会造成request冲突 那么解决的办法就是把该request排除出去 不让struts2拦截
- CentOS 6.5 IP 设置
DEVICE=eth0TYPE=EthernetUUID=7d6d54e0-054d-472b-8cc1-080f16ef36c1ONBOOT=yesNM_CONTROLLED=yesBOOTPROT ...
- 在静态页面html中跳转传值
在html中通过"?"传值--------<a href="index2.html?name=caoy">静态传值</a> 在跳转到的页 ...
- linux 定时执行shell
第一步:安装 crontab ,命令 yum -y install vixie-cron 扩展:service crond start //启动服务 ...