HDU 2056 JAVA
2017-03-05 10:29
134 查看
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
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 cin = new Scanner(System.in); while (cin.hasNext()) { double t; double sum = 0.0; double x1 = cin.nextDouble(); double y1 = cin.nextDouble(); double x2 = cin.nextDouble(); double y2 = cin.nextDouble(); double x3 = cin.nextDouble(); double y3 = cin.nextDouble(); double x4 = cin.nextDouble(); double y4 = cin.nextDouble(); 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; } x1 = max(x1, x3); x2 = min(x2, x4); y1 = max(y1, y3); y2 = min(y2, y4); if (x1 > x2 || y1 > y2) { System.out.println("0.00"); } else { sum = (x2 - x1) * (y2 - y1); System.out.printf("%.2f", sum); System.out.println(); } } } private static double min(double x2, double x4) { if (x2 < x4) return x2; else return x4; } private static double max(double x1, double x3) { if (x1 > x3) return x1; else return x3; } }
相关文章推荐
- HDU 3546(高精度,java写)
- HDU 菲波数 JAVA大数。。。第一个!!~~~
- HDU-1573 大明A+B Java
- HDU-1212 Big Number JAVA又出毛病了
- hdu 1753 java 小数相加
- HDU1130_How Many Trees?(卡特兰数 _java)
- HDU-1715 大菲波数 Java
- 【Java】hdu 4043
- HDU高精度总结(java大数类)
- hdu 1175 连连看 java (BFS + 一搜到底)
- hdu 1002 大数之java小试牛刀
- hdu 1313 (Java)
- HDU-1063 Exponentiation Java
- hdu java 大数 转载
- hdu 1728 逃离迷宫 java BFS + 一搜到底
- http://acm.hdu.edu.cn/showproblem.php?pid=2303 (素数打表 + java大数取模)
- hdu 2056 -- Rectangles (矩形重合)
- HDU-1316 How Many Fibs? Java
- hdu 1063 java 高精度
- hdu 1003 java 开一维数组