Dwarven sniper's hunting
Problem descriptionnow the hunting starts in the world named Dota, a stupid PC game which cannot play with others together.
Among the individuals in the game, there are two heroes named Dwarven sniper and lycanthrope. lycanthrope wants to escape from being captured; however, our Dwarven sniper won't let him go! He will use the silver bullet to kill the lycanthrope by only one shot! Yes, that's enough.
Lycanthrope is running on a line in the map with a constant speed and direction. the weapon range of the silver bullet is limited by L meters. dwarven sniper can run for a while freely, and then shoot lycanthrope. in order to show his excellent shooting skill, Dwarven sniper wants the silver bullet flying as far as possible. but don't forget the flying time of the silver bullet due to considerable weight of the bullet. and Dwarven sniper wants to stop the hunting as quickly as possible. so if there is more than one way to show his excellent skill, he wowould choose the fastest way. in this problem we consider the silver bullet and lycanthrope as two points.
Now Dwarven sniper wants to know the maximum length that the silver bullet can fly, and the shortest time that the hunting lasts. specifically, the total hunting time is defined as the time interval from the start of hunting to the moment that the bullet hit lycanthrope. can you help him?
Inputthere are several test cases. each of them contains only one line which consist of 9 real numbers, that are x1, Y1, X2, Y2, lx, Ly, Vd, VB and L (-10000 <= x1, y1, X2, Y2, lx, Ly <= 10000, 0 <= VD, VB, L <= 100000 ).
The pair (x1, Y1) is the starting position of the lycanthrope while (X2, Y2) is the starting position of dwarven sniper.
(LX, ly) is the moving vector per second of the lycanthrope.
VD is the speed of the Dwarven sniper.
VB is the speed of the silver bullet.
All units are meters/second.
It is guaranteed that (LX * lx + ly * ly) <vd * vd <Vb * Vb, and Dwarven sniper's starting position is different from lycanthrope's position. the input ends with a line containing all zeros.
Outputfor each test case, output two real numbers S and T in a line separated by a single space denoting that the silver bullet flies s meters before hitting lycanthrope and the hunting lasts for T seconds, both with 3 digits after the decimal point.
You may assume that Dwarven sniper can finish his hunting within no more than 1E + 9 seconds.
Sample Input
-1 0 0 10 1 0 2 10 100 0 0 5 0 1 2 6 60 0 0 0 0 0 0 0 0
Sample output
10.000 1.0006.000 3.000
Sourcethe 36th ACM/ICPC Asia Regional Shanghai site -- online contest
Recommendlcy | we have carefully selected several similar problems for you: 4022 4021 4023 4025
Question:
D: kill L. D is a remote hero. D can send a skill with a distance of L. It is known that the starting position of the hero l is X1, Y1, and the moving speed vector is lx, Ly, the starting position of D is X2, Y2, and D. The moving speed of D is VD, and that of D is VB (LX * lx + ly * ly) <vd * vd <Vb * Vb: How long does it take to kill L when D fully demonstrates his shooting ability?
Solution:
Because :( lx * lx + ly * ly) <vd * vd <Vb * Vb, that is, l's moving speed <D's moving speed <bow and arrow's moving speed. That is to say, if D shows his own capabilities, the longest distance of a certain shot is l, so how to calculate the time can be divided into two answers.
Solution code:
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;// X1, Y1, X2, Y2, Lx, Ly, vD , vB and Lconst double eps=1e-7;double X1,Y1,X2,Y2,lx,ly,vd,vb,L;double getdis(double ax,double ay,double bx,double by){ return sqrt ( (ax-bx)*(ax-bx)+(ay-by)*(ay-by) );}double getmin(double ans1,double ans2){ if(ans1<-eps) return ans2; if(ans2<-eps) return ans1; return min(ans1,ans2);}void solve(){ double l=L/vb,r=1e9; while(r-l>eps){ double mid=(l+r)/2; double X0=X1+mid*lx,Y0=Y1+mid*ly; double dis0=getdis(X0,Y0,X2,Y2); double disd=vd*(mid-L/vb); if(dis0<=L){ if(disd+dis0<=L) l=mid; else r=mid; }else{ if(disd+L>=dis0) r=mid; else l=mid; } } printf("%.3lf %.3lf\n",L,(r+l)/2);}int main(){ while(cin>>X1>>Y1>>X2>>Y2>>lx>>ly>>vd>>vb>>L){ if( fabs(X1)<eps && fabs(X2)<eps && fabs(Y1)<eps && fabs(Y2)<eps ){ if( fabs(lx)<eps && fabs(ly)<eps && fabs(vd)<eps && fabs(vb)<eps && fabs(L)<eps ) break; } solve(); } return 0;}