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的更多相关文章

  1. HDOJ(2056)&HDOJ(1086)

    Rectangles    HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...

  2. HDU 2056 Rectangles

    Rectangles Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. 杭电oj2047-2049、2051-2053、2056、2058

    2047  阿牛的EOF牛肉串 #include<stdio.h> int main(){ int n,i; _int64 s[]; while(~scanf("%d" ...

  4. 【HDOJ】1510 White Rectangles

    这个题目很好,变形的题目也很多.简单DP. /* 1510 */ #include <cstdio> #include <cstring> #include <cstdl ...

  5. hdoj:2056

    #include <iostream> #include <iomanip> #include <cstdlib> using namespace std; str ...

  6. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  8. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  9. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

随机推荐

  1. dedecms 5.7文章编辑器附件上传图标不显示

    我最近发现在使用dedecms 5.7文章编辑器附件上传图标不显示了,以前是没有问题的,这个更新系统就出来问题了,下面我来给大家分享此问题解决办法.   问题bug:在dedecms 5.7中发现了一 ...

  2. IsPostBack and DropdownList.

    Encounted the issue accident when helping my classmate dealing with his homework assignment,it turns ...

  3. [转]Delphi I/O Errors

    The following are the Windows API (and former DOS) IO errors, which are also the IO errors often ret ...

  4. Java线程(学习整理)--1--守护线程

    1.什么是守护线程? 今天老师讲解我才知道有守护线程这回事!原来守护线程经常存在于我们的身边,比如:一个免费的网页游戏,里面都会或多或少有些插入性的广告!! 一般情况下,我们不会去点击这些广告的,但是 ...

  5. Spring 创建bean的时机

    默认在启动spring容器的时候,spring容器配置文件中的类就已经创建完成对象了        在<bean>中添加属性lazy-init,默认值为false.    true  在c ...

  6. 第七篇、Nginx Install On Mac

    方式一: 在mac上安装nginx,依次安装对应的依赖 pcre ./configure --prefix=/usr/local/pcre-8.37 --libdir=/usr/local/lib/p ...

  7. apache rewrite .htaccess 站点内容重定向实例

    <IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_FILENA ...

  8. CSS Hack技术详解,支持IE 6-11、Chrome、FireFox、Safari、Opera 6-11、Chrome、FireFox、Safari、Opera6-11、Chrome、FireFox、Safari、Opera6-11、Chrome、FireFox、Safari、Opera

    转自: http://www.365mini.com/page/css-hack-ie-chrome-firefox-safari-opera.htm 当前网络时代,各种各样的网页向我们展示着丰富多彩 ...

  9. laravel框架——线上环境错误总结

    除了根目录,其他目录访问全是Not Found

  10. isKindOfClass:和isMemberOfClass:-b

    isKindOfClass: Returns a Boolean value that indicates whether the receiver is an instance of given c ...