简单二分,最大射击距离是必然能达到的,只要在能到达最大距离的瞬间就立刻射击可以保证时间最短。
#include <string.h> #include <stdio.h> #include <math.h> double xx1,yy1,xx2,yy2,lx,ly,vd,vb,l; double sqr(double x){return x*x;} double getdis(double xx1,double yy1,double xx2,double yy2){ return sqrt(sqr(xx1-xx2)+sqr(yy1-yy2)); } int canreach(double t){ double dis=getdis(xx2,yy2,xx1+t*lx,yy1+t*ly); return vd*(t-l/vb)>=fabs(dis-l); } int main(){ freopen("test.in","r",stdin); while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf",&xx1,&yy1,&xx2,&yy2,&lx,&ly,&vd,&vb,&l)){ if(xx1+yy1+xx2+yy2+lx+ly+vd+vb+l==0)break; double low=l/vb,high=1e9,mid; while(high-low>1e-7){ mid=(low+high)/2; if(canreach(mid))high=mid; else low=mid; } printf("%.3f %.3f\n",l,mid); } return 0; }