題目描述:求飛機聲音堵塞耳朵的時間,飛機前t秒要飛到高度H,速度不能超過v,能夠堵塞耳朵的最小速度是x,求飛機聲音堵塞耳朵的時間的最大時間和最小時間。
解題思路:
如果h/t >x , 則最大時間是t,反之則是h/x,做小時間由方程解出: x*t1+v*t2=h, t1+t2=t;
解得 t2=(h-t*x)/(v-x);另外需要注意一個地方,這個式子分子<0的時候,應該輸出0.被這個地方坑過。另外此題的樣例給錯了,坑了我們從頭到尾。直接輸出六位小數就行。
代碼如下:
#include <cstdio>
#include <string>
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
const double esp = 1e-6;
int main()
{
double h, t, v, x;
cin >> h >> t >> v >> x;
double minn = (h-t*x)/(v-x);
double maxx = h/t<=x? h/x : t;
cout << setiosflags(ios::fixed) << setprecision(6) << (minn<0?0:minn) << ' ' << maxx << endl;
return 0;
}