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. Z-Stack 软件架构分析

    转自Z-Stack 软件架构分析 Z-Stack的main函数在Zmain.c中,总体上来说,它一共做了两件工作,一个是系统初始化,即有启动代码来初始化硬件系统和软件架构需要的各个模块,另一个作用就是 ...

  2. 单片机系统与标准PC键盘的接口模块设计

    转自单片机系统与标准PC键盘的接口模块设计 概述     在单片机系统中,当输入按键较多时,在硬件设计和软件编程之间总存在着矛盾.对于不同的单片机系统需要进行专用的键盘硬件设计和编程调试,通用性差,使 ...

  3. 通过live555实现H264 RTSP直播

    http://blog.csdn.net/firehood_/article/details/16844397

  4. Android用户界面 UI组件--自动提示输入框 AutoCompleteTextView和MultiAutoCompleteTextView

    AutoCompleteTextView: 就是一个带自动提示的EditText,当输入字符时,会出现提示. android:completionThreshold  输入几个字符时提示 androi ...

  5. 翻译文章“AST 模块:用 Python 修改 Python 代码”---!!注意ironpathyon未实现此功能

    https://github.com/upsuper/blog/commit/0214fdd084c4adf2de2ed9912d644fb59ce13a1c +Title: [翻译] AST 模块: ...

  6. Java函数参数传递方式详解

    在阅读本文之前,根据自己的经验和理解,大家可以先思考并选择一下Java函数的参数传递方式: A. 是按值传递的? B. 按引用传递的? C. 部分按值部分按引用? 此处暂不宣布正确答案,我们通过一个简 ...

  7. jQuery对象和DOM对象原来不一样啊

    jQuery对象和DOM对象使用说明,需要的朋友可以参考下.1.jQuery对象和DOM对象第一次学习jQuery,经常分辨不清哪些是jQuery对象,哪些是 DOM对象,因此需要重点了解jQuery ...

  8. Action中取得request,session的四种方式

    Action中取得request,session的四种方式 在Struts2中,从Action中取得request,session的对象进行应用是开发中的必需步骤,那么如何从Action中取得这些对象 ...

  9. LR测试工具性能指标详解

    这篇文章将对LoadRunner测试工具的性能指标从以下三点进行详解. 第一点.Web资源分析是从服务器入手对Web服务器的性能分析. 1.Hits per Second "每秒点击次数&q ...

  10. c# 如何通过反射 获取\设置属性值

    c# 如何通过反射 获取\设置属性值 //定义类public class MyClass{public int Property1 { get; set; }}static void Main(){M ...