題目連接:http://acm.hdu.edu.cn/showproblem.php?pid=5761
【題意】船在(0,a),存在一個恆定向右的速度v2,一個始終指向源點的速度v1,問到達源點的時間。無法到達輸出Infinity。
【分析】方法來自題解
設船到原點的距離是r,容易列出方程
dtdr=v2cosθ−v1
dtdx=v2−v1cosθ
上下界都是清晰的,定積分一下:
0−a=v2∫0Tcosθdt−v1T
0−0=v2T−v1∫0Tcosθdt
直接把第一個式子代到第二個裏面
v2T=v2v1(−a+v1T)
T=v12−v22v1a
【代碼】
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
int a,v1,v2;
while(~scanf("%d %d %d",&a,&v1,&v2)){
if(a==0){
printf("%.010lf\n",0);
continue;
}
if(v1<=v2){
cout<<"Infinity\n";
continue;
}
double ans=a*v1;
double tmp1=v1;
double tmp2=v2;
tmp1*=tmp1;
tmp2*=tmp2;
ans/=(tmp1-tmp2);
printf("%.010lf\n",ans);
}
}