Rectangles

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 20375    Accepted Submission(s):
6607

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;

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;
}
}

这个地方要注意的是的判断一下图形是否相交,如果不相交,还是要输出按题目中的输出要求:0.00;不然就会出错,这个题目只有相交和分离两种状态;

HDU2056JAVA的更多相关文章

随机推荐

  1. phpStorm 配置关联php手册

    phpStorm 配置关联php手册 pasting php开发中我尝试过很多个编辑器,但用的最多的是phpStorm ,但一直因为英文太烂,很多phpStorm功能,都没用过.. 最近发现有些编辑器 ...

  2. Multiplication Puzzle

    题目大致意思是:一个整数序列包含N个1~100的整数(3<=N<=100),从中取出一个数并和相邻两边的整数相乘,依次进行下去直到只剩下首尾两个数为止,求最终的得到的和的最小值.两边的数不 ...

  3. 解决crystal report水晶报表在浏览器提示bobj未定义的错误

    网上的中文文章(比如这篇文章)都是写的部署到服务器后出现的问题,同时也指出要把crystal report的aspnet_client文件夹拷贝到对应项目的根目录里,这样就可以正常显示了,但是具体到我 ...

  4. Android中的常见时区

    方法: private void printTimeZone(){ String[] ids= TimeZone.getAvailableIDs(); for (int i = 0; i < i ...

  5. How to hide TabPage from TabControl

    No, this doesn't exist. You have to remove the tab and re-add it when you want it. Or use a differen ...

  6. flexPaper +swftools实现文档在线阅读

    网上已有很多FlexPaper仿百度文库的一些文章,园子里也有很多大牛的详细教程. 结合这次做的例子,在这里详细记录一下使用Flexpaper实现仿百度文库的效果,及自己在跟着园子里的教程做的时候,遇 ...

  7. Retina

    走向Retina Web RETINA时代的前端优化 <!DOCTYPE html> <html> <head> <meta charset="ut ...

  8. 1px

    Retina屏的移动设备如何实现真正1px的线? <!DOCTYPE html> <html> <head> <meta charset="utf- ...

  9. ARM学习笔记6——程序状态寄存器访问指令

    这两条指令结合,可用于对CPSR或SPSR进行读/写操作. 当需要保存或修改当前模式下CPSR或SPSR的内容时,首先必须将这些内容传递到通用寄存器中 1.MRS指令(Move to Register ...

  10. HDOJ/HDU 1085 Holding Bin-Laden Captive!(非母函数求解)

    Problem Description We all know that Bin-Laden is a notorious terrorist, and he has disappeared for ...