HDU2056JAVA
Rectangles
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 20375 Accepted Submission(s):
6607
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 .
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).
intersected part in a single line.accurate up to 2 decimal places.
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的更多相关文章
随机推荐
- BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐
Description The cows are having a picnic! Each of Farmer John's K (1 <= K <= 100) cows is graz ...
- MDN > Web technology for developers > HTTP
The Hypertext Transfer Protocol (HTTP) is an application-layer protocol for transmitting hypermedia ...
- PYTHON不定参数与__DOC__
def total(initial = 5, *numbers, **keywords): count = initial for number in numbers: count += number ...
- 在android4.0中实现View的拖动效果
实现方法: 首先需要定义一个支持拖动的源组件和一个作为Drop区域的目标组件. 在支持拖动的组件中注册OnTouchListener 或LongClickListener监听事件,构建一个ClipDa ...
- android 世界各国英文简写代码 资源文件
今日又用到这段代码,忽然感觉到如果是第一次用的人肯定也会很麻烦.故在此上传一份.后人再用就不必重复做此工作.跟体育老师学过语文,见谅. 提供下载地址 http://download.csdn.net/ ...
- bzoj1197
水题,画个图推一下低维的就什么都明白了 从低维类推高维 ..,..] of int64; n,m,j,i:longint; begin readln(m,n); to n do f[i,]:=; to ...
- C#文本处理(String)学习笔记
摘要:string是编程中使用最频繁的类型.一个string表示一个恒定不变的字符序列集合.string类型直接继承自object,故他是一个引用类型,也就是说线程的堆栈上不会有任何字符串(直接继承自 ...
- BJOI2006狼抓兔子
1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 9967 Solved: 2267[Submit][S ...
- BZOJ1345: [Baltic2007]序列问题Sequence
1345: [Baltic2007]序列问题Sequence Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 556 Solved: 274[Submi ...
- Hay Points
Hay Points TimeLimit: 1 Second MemoryLimit: 32 Megabyte Totalsubmit: 1022 Accepted: 602 Descript ...