• 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("Dangerous
    ");
     90     else if(d-esp>du)  printf("Miss
    ");
     91     else printf("Perfect
    ");
     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 }
    View Code
  • 相关阅读:
    一些开源工具软件
    被伤过的心还可以爱谁
    C函数检测CPU架构为LittleEndian或BigEndian
    C#打印(接录)
    C#Lambda表达式参考
    C#反射 创建对象,调用方法
    datagridview cell 验证事件
    我多想抱着你哭
    C#获取属性
    STM32的位操作的方法
  • 原文地址:https://www.cnblogs.com/gongxijun/p/3849595.html
Copyright © 2020-2023  润新知