标签:des style blog http java color
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 196 Accepted Submission(s): 48
代码:
1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #include<math.h> 5 const int MAX=0x3f3f3f3f ; 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=(w2.y-w1.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 b1.y=a1.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\n"); 90 else if(d-esp>du) 91 printf("Miss\n"); 92 else 93 printf("Perfect\n"); 94 } 95 int main() 96 { 97 while(scanf("%lf",&w1.x)!=EOF) 98 { 99 scanf("%lf%lf%lf%lf",&w1.y,&w2.x,&w2.y,&vw); 100 scanf("%lf%lf%lf%lf%lf",&t1.x,&t1.y,&t2.x,&t2.y,&vt); 101 scanf("%lf%lf",&dl,&du); 102 work(); 103 } 104 return 0; 105 }
hdu------2488Tornado(几何),布布扣,bubuko.com
标签:des style blog http java color
原文地址:http://www.cnblogs.com/gongxijun/p/3849595.html