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. C# 枚举

    一.在学习枚举之前,首先来听听枚举的优点. 1.枚举能够使代码更加清晰,它允许使用描述性的名称表示整数值. 2.枚举使代码更易于维护,有助于确保给变量指定合法的.期望的值. 3.枚举使代码更易输入. ...

  2. 【POJ1417】【带标记并查集+DP】True Liars

    Description After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was ...

  3. 行列的几种命名方式.line-.colume======.row-.col=========.tr-.td

    第一种从line-height的语义来来讲,line表示hang再贴切不过了,colume纵列或者柱子也很形象,缺点太长了 第二种组合模拟rowspan,colspan而来,想必这个col也是colu ...

  4. javascript DOM艺术

    一.DOM基础1.节点(node)层次Document--最顶层的节点,所有的其他节点都是附属于它的.DocumentType--DTD引用(使用<!DOCTYPE>语法)的对象表现形式, ...

  5. magento前台访问错误

    前台访问出现错误 General error: 145 Table './dbname/tablename' ismarked as crashed and should be repaired 解决 ...

  6. 常用排序算法集合-C实现

    之前熟悉C的时候写着玩的,就当做笔记用吧: #include<stdio.h> #include<stdlib.h> #include<string.h> #inc ...

  7. 使用iOS8 WKWebView的浏览器模块,脉冲动画层-b

    KINWebBrowser是一个可嵌入app的浏览器模块. 它使用iOS 8的 WKWebView API编写,同时在iOS 7上使用UIWebView来兼容. 测试环境: Xcode 6.0 iOS ...

  8. C++例题1:输出可打印字符

    #include<iostream>#include<stdlib.h>#include<cctype>int main(){ int i;char a=0; fo ...

  9. mapreduce (四) MapReduce实现Grep+sort

    1.txt dong xi cheng xi dong cheng wo ai beijing tian an men qiche dong dong dong 2.txt dong xi cheng ...

  10. 【转】JQUERY相关的几个网站

    作者:Terry li - GBin1.com 1. John Resig - http://ejohn.org 毫无疑问,jQuery 的缔造者的博客是你首先必须关注的. 2. Filmament ...