标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 685 Accepted Submission(s): 248
Special Judge
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 #define eps 1e-8 /* >0:>eps--- <0:<-eps */ 7 #define zero(x)(((x)>0?(x):-(x))<eps) 8 #define PI acos(-1.0) 9 #define LL long long 10 #define maxn 100100 11 #define IN freopen("in.txt","r",stdin); 12 using namespace std; 13 14 int sign(double x) 15 { 16 if(fabs(x)<eps) return 0; 17 return x<0? -1:1; 18 } 19 20 double Rm,R,r,x,y,vx,vy; 21 double v; 22 23 int main(int argc, char const *argv[]) 24 { 25 //IN; 26 27 while(scanf("%lf%lf%lf%lf%lf%lf%lf",&Rm,&R,&r,&x,&y,&vx,&vy)!=EOF) 28 { 29 double a,b,c,del; 30 a = vx*vx+vy*vy; 31 b = 2.0*x*vx + 2.0*y*vy; 32 c = x*x + y*y - (R+r)*(R+r); 33 34 del = (b*b - 4.0*a*c); 35 if(sign(del)<=0) {printf("0\n");continue;} 36 37 del=sqrt(del); 38 double t1,t2; 39 t1 = (-b+del)/(2.0*a);t2 = (-b-del)/(2.0*a); 40 if(t1>t2) swap(t1,t2); 41 if(t1<0) {printf("0\n");continue;} 42 43 a = vx*vx+vy*vy; 44 b = 2.0*x*vx + 2.0*y*vy; 45 c = x*x + y*y - (Rm+r)*(Rm+r); 46 47 del = (b*b - 4.0*a*c); 48 if(sign(del)<=0) {printf("%.3lf\n",fabs(t1-t2));continue;} 49 50 del=sqrt(del); 51 double t3,t4; 52 t3 = (-b+del)/(2.0*a);t4 = (-b-del)/(2.0*a); 53 if(t3>t4) swap(t3,t4); 54 if(t3<0) {printf("%.3lf\n",fabs(t1-t2));continue;} 55 56 printf("%.3lf\n",2.0*fabs(t3-t1)); 57 } 58 59 return 0; 60 }
HDU 4793 Collision (2013长沙现场赛,简单计算几何)
标签:
原文地址:http://www.cnblogs.com/Sunshine-tcf/p/4926613.html