hdu------2488Tornado(几何)
Tornado
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 196 Accepted Submission(s): 48
Problem Description
Professor Jonathan is a well-known Canadian physicist and meteorologist. People who know him well call him “Wind Chaser”. It is not only because of his outstanding tornado research which is the most influential in the academic community, but also because of his courageous act in collecting real data of tornados. Actually he has been leading his team chasing tornado by cars equipped with advanced instruments hundreds of times. In summer, tornado often occurs in the place where Professor Jonathan lives. After several years of research, Wind Chaser found many formation rules and moving patterns of tornados. In the satellite image, a tornado is a circle with radius of several meters to several kilometers. And its center moves between two locations in a straight line, back and forth at a fixed speed. After observing a tornado’s movement, Wind Chaser will pick a highway, which is also a straight line, and chase the tornado along the highway at the maximum speed of his car. The smallest distance between the Wind Chaser and the center of the tornado during the whole wind chasing process, is called “observation distance”. Observation distance is critical for the research activity. If it is too short, Wind Chaser may get killed; and if it is too far, Wind Chaser can’t observe the tornado well. After many times of risk on lives and upset miss, Wind Chaser turns to you, one of his most brilliant students, for help. The only thing he wants to know is the forthcoming wind chasing will be dangerous, successful or just a miss.
Input
Input contains multiple test cases. Each test case consists of three lines which are in the following format. xw1 yw1 xw2 yw2 vw xt1 yt1 xt2 yt2 vt dl du In the first line, (xw1, yw1) means the start position of Wind Chaser; (xw2, yw2) is another position in the highway which Wind Chaser will definitely pass through; and vw is the speed of the car. Wind chaser will drive to the end of the world along that infinite long highway. In the second line, (xt1, yt1) is the start position of tornado; (xt2, yt2) is the turn-around position and vt is the tornado’s speed. In other words, the tornado’s center moves back and forth between (xt1, yt1) and (xt2, yt2) at speed vt . The third line shows that if the observation distance is smaller than dl , it will be very dangerous; and if the observation distance is larger than du, it will be a miss; otherwise it will lead to a perfect observation. All numbers in the input are floating numbers. -2000000000 <= xw1, yw1, xw2, yw2, xt1, yt1, xt2, yt2 <= 2000000000 1 <= vw, vt <= 20000 0 <= dl, du <= 2000000 Note: 1. It’s guaranteed that the observation distance won’t be very close to dl or du during the whole wind chasing process. There will be at least 10-5 of difference. 2. Wind Chaser and the tornado start to move at the same time from their start position.
Output
For each test case output one line contains one word “Dangerous”, “Perfect” or “Miss” which describes the prediction of the observation.
Sample Input
0 0 1 0 2 10 -5 12 7 4 1.3 2.7 0 0 1 0 2 10 -5 12 7 1 0.3 0.4
Sample Output
Dangerous Perfect
Source
Recommend
gaojie | We have carefully selected several similar problems for you: 2490 2494 3254 2267 1755
代码:
1 #include<stdio.h>
2 #include<string.h>
3 #include<stdlib.h>
4 #include<math.h>
5 const int MAX=1000000000 ;
6 const double esp = 1e-7;
7
8 struct Tnode
9 {
10 double x,y;
11 }w1,w2,t1,t2;
12 double vw,vt,dl,du;
13 double getmin(double a , double b)
14 {
15 return (a>b)?b:a;
16 }
17 //求点积
18 double dianji(Tnode &a ,Tnode &b ,Tnode &c)
19 {
20 return (b.x-a.x)*(c.x-a.x)+(b.y-a.y)*(c.y-a.y);
21 }
22 //求叉 积
23 double det(Tnode &a ,Tnode &b ,Tnode &c)
24 {
25 return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
26 }
27 //求距离
28 double dis(Tnode &a,Tnode &b)
29 {
30 return sqrt(fabs((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y)));
31 }
32 //求点o到线段的最近的距离
33 double getdistance(Tnode &o,Tnode a ,Tnode b,double dx,double dy)
34 {
35 a.x+=dx;
36 a.y+=dy;
37 b.x+=dx;
38 b.y+=dy;
39 double d =getmin(dis(o,a),dis(o,b));
40 double di=dis(a,b);
41 if(di<=esp) return dis(o,a);
42 if(dianji(a,o,b)>=-esp&&dianji(b,o,a)>=-esp)
43 return fabs(det(a,b,o))/di;
44 else
45 return getmin(dis(o,a),dis(o,b));
46 }
47 //求o到以线段ab为起始,(dx,dy)为间距的平行线段的最近距离
48 double calc(Tnode &o ,Tnode &a ,Tnode &b , double dx, double dy)
49 {
50 Tnode a1,b1;
51 int ll=0,rr=MAX;
52 while(ll<rr)
53 {
54 int mid=(ll+rr)/2;
55 double d1=getdistance(o,a,b,dx*mid,dy*mid);
56 double d2=getdistance(o,a,b,dx*(mid+1),dy*(mid+1));
57 if(d1<=d2+esp) rr=mid;
58 else ll=mid+1;
59 }
60 return getdistance(o,a,b,dx*ll,dy*ll);
61 }
62 void work()
63 {
64 Tnode wdr ,tdr,move,a1,b1,a2,b2;
65 double distance,time,d,d1,d2;
66 distance=dis(w1,w2);
67 wdr.x = (w2.x-w1.x)*vw/distance;
68 wdr.y = (w2.y-w1.y)*vw/distance;
69 distance = dis(t1,t2);
70 time = distance/vt;
71 tdr.x = (t2.x-t1.x)*vt/distance;
72 tdr.y=(t2.y-t1.y)*vt/distance;
73 move.x=(-wdr.x+tdr.x)*time;
74 move.y=(-wdr.y+tdr.y)*time;
75 //求两个线段簇的第一条线段a1-b1和a2-b2
76 a1=t1;
77 b1.x=a1.x+move.x;
78 b1.y=a1.y+move.y;
79 move.x=(-wdr.x-tdr.x)*time;
80 move.y=(-wdr.y-tdr.y)*time;
81 a2=b1;
82 b2.x=a2.x+move.x;
83 b2.y=a2.y+move.y;
84 //分别求点w1到两个线段簇的最近距离d1和d3
85 d1=calc(w1,a1,b1,b2.x-a1.x,b2.y-a1.y);
86 d2=calc(w1,a2,b2,b2.x-a1.x,b2.y-a1.y);
87 //判断结果
88 d=getmin(d1,d2);
89 if(d+esp<d1) printf("Dangerousn");
90 else if(d-esp>du) printf("Missn");
91 else printf("Perfectn");
92 }
93 int main()
94 {
95 while(scanf("%lf",&w1.x)!=EOF)
96 {
97 scanf("%lf%lf%lf%lf",&w1.y,&w2.x,&w2.y,&vw);
98 scanf("%lf%lf%lf%lf%lf",&t1.x,&t1.y,&t2.x,&t2.y,&vt);
99 scanf("%lf%lf",&dl,&du);
100 work();
101 }
102 return 0;
103 }
- 临时表相关 (r4笔记第52天)
- Java基础-08(02)总结帮助文档,代码块,继承
- java中堆和栈的区别
- 通过shell来比较oracle和java中的字符串使用(r4笔记第49天)
- Java 单例以及单例所引发的思考
- AJAX跨域完全讲解
- 最简单的web服务器实现(一)(r4笔记第68天)
- 算法09 五大查找之:哈希查找
- JSP面试题都在这里
- Java基础-07(01).总结private,this,封装,static,成员方法变量,局部变量匿名对象
- HTTP就是这么简单
- 重温二分查找算法(r4笔记第66天)
- 【不用框架】文件上传和下载
- JSP第七篇【简单标签、应用、DynamicAttribute接口】
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- WMCTF2020 部分Writeup&招新帖
- 【DB宝15】生产环境中,如何利用DG的备库来异机还原一个新库?
- Java命令执行学习笔记
- SAP UI5应用DatePicker控件的设计明细
- 如何根据自己的实际需求开发属于自己的sublime text插件
- Sony Z13 系列笔记本安装 NVIDIA 官方最新版显卡驱动程序
- 通过网页进行 iOS 应用内部分发
- 【DB笔试面试853】在Oracle中,什么是手动建库?手动建库有哪些步骤?
- 使用 Intel HAXM 为 Android 模拟器加速,媲美真机
- NHibernate 使用 SqlQuery
- 谈谈 INotifyPropertyChanged 的实现
- C 语言小知识
- 使用代码配置 NHibernate
- [Introduction]Go特殊的引用类型:值传递/指针传递/引用传递
- PythonforResearch | 0_语法基础