Rower Bo is placed at (0,a) at first.He wants to get to origin (0,0) by boat.Boat speed relative to water is v1 ,and the speed of the water flow is v2 .He will adjust the direction of v1 to origin all the time.
Your task is to calculate how much time he will use to get to origin.Your answer should be rounded to four decimal places.
If he can't arrive origin anyway,print"Infinity"(without quotation marks).
For each test case,there is only one line containing three integers a,v1,v2 .
0≤a≤100 , 0≤v1,v2,≤100 , a,v1,v2 are integers
If the absolute error between your answer and the standard answer is no more than 10−4 , your solution will be accepted.
2 3 3 2 4 3
Infinity 1.1428571429
首先这个题微分方程强解显然是可以的,但是可以发现如果设参比较巧妙就能得到很方便的做法。
先分解v1v_1v1,
设船到原点的距离是rrr,容易列出方程
drdt=v2cosθ−v1\frac{ dr}{ dt}=v_2\cos \theta-v_1dtdr=v2cosθ−v1
dxdt=v2−v1cosθ\frac{ dx}{ dt}=v_2-v_1\cos \thetadtdx=v2−v1cosθ
上下界都是清晰的,定积分一下:
0−a=v2∫0Tcosθdt−v1T0-a=v_2\int_0^T\cos\theta{ d}t-v_1T0−a=v2∫0Tcosθdt−v1T
0−0=v2T−v1∫0Tcosθdt0-0=v_2T-v_1\int_0^T\cos\theta{ d}t0−0=v2T−v1∫0Tcosθdt
直接把第一个式子代到第二个里面
v2T=v1v2(−a+v1T)v_2T=\frac{v_1}{v_2}(-a+v_1T)v2T=v2v1(−a+v1T)
T=v1av12−v22T=\frac{v_1a}{{v_1}^2-{v_2}^2}T=v12−v22v1a
这样就很Simple地解完了,到达不了的情况就是v1<v2v_1< v_2v1<v2(或者a>0a>0a>0且v1=v2v_1=v_2v1=v2)。
#include <iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
double a,v1,v2;
while(~scanf("%lf%lf%lf",&a,&v1,&v2))
{
if(a==0) printf("0\n");
else if(v1>v2) printf("%.10f\n",(double)a*v1/(v1*v1-v2*v2));
else printf("Infinity\n");
}
}