题目链接
一道三分查找的题,首先推出公式即可,需要的时间t是l/(v*cos(th)),所以高度就是v*sin(th)*t-g/2*t*t。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define lowbit(x) ( x&(-x) )
#define pi 3.141592653589793
#define e 2.718281828459045
using namespace std;
typedef long long ll;
const double g=9.80;
double h, l, v;
double Li, Ri, LMid, RMid;
double Abs(double x) { return x>0?x:(-x); }
double solve(double th) { return l*sin(th)/cos(th)-g/2.*l*l/(v*v*cos(th)*cos(th)); }
void Erfen()
{
while(Ri-Li>1e-4)
{
LMid=Li+(Ri-Li)/3.; RMid=Ri-(Ri-Li)/3.;
if(solve(LMid)<=solve(RMid)) Li=LMid;
else Ri=RMid;
}
}
int main()
{
while(scanf("%lf%lf%lf", &h, &l, &v)!=EOF)
{
if(h==0 && l==0 && v==0) break;
Li=0; Ri=90.;
Erfen();
printf("%.2lf\n", h+solve((Li+Ri)/2.));
}
return 0;
}