CodeForces 590B Chip 'n Dale Rescue Rangers
这题可以o(1)推出公式,也可以二分答案+验证。
#include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> using namespace std; double X1,X2,Y1,Y2; double v,t; double vx,vy,wx,wy; bool check(double mid) { double tmpx,tmpy; if(mid<=t) { tmpx=X1+mid*vx; tmpy=Y1+mid*vy; double dis=sqrt((X2-tmpx)*(X2-tmpx)+(Y2-tmpy)*(Y2-tmpy)); if(dis/v>mid) return 0; return 1; } else { tmpx=X1+t*vx; tmpy=Y1+t*vy; tmpx=tmpx+(mid-t)*wx; tmpy=tmpy+(mid-t)*wy; double dis=sqrt((X2-tmpx)*(X2-tmpx)+(Y2-tmpy)*(Y2-tmpy)); if(dis/v>mid) return 0; return 1; } } int main() { scanf("%lf%lf%lf%lf",&X1,&Y1,&X2,&Y2); scanf("%lf%lf",&v,&t); scanf("%lf%lf%lf%lf",&vx,&vy,&wx,&wy); double l=0,r=9999999999; double ans; int t=200; while(t--) { double mid=(l+r)/2.0; if(check(mid)) { ans=mid; r=mid; } else l=mid; } printf("%.18lf\n",ans); return 0; }