http://acm.hdu.edu.cn/showproblem.php?pid=2298
分析:斜抛运动:http://baike.baidu.com/link?url=JYIT2a6cWniYW7UfTHTYFOxf_B-D2noUxnLIRTRTrydpixDeq8s_mGvdH7N1hfre
斜抛运动轨迹方程式:y=xtanθ-gx^2/2(v0cosθ)^2,其中x:某时刻该点水平位移,y:竖直位移(即:果子位置)
三分查找:判断是否能达到果子的位置,找最大能达到的高度
二分查找:寻找能达到y的角度
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const double G=9.8;
const double ans=1e-9; //精度
const double PI=acos(-1.0);
double x,y,v;
double Fx(double t)
{
return x*tan(t)-G*x*x/(2*v*v*cos(t)*cos(t));
}
int main()
{
double low,high,mid,mmid,my;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%lf%lf%lf",&x,&y,&v);
low=0,high=PI/2;
while(high-low>ans)
{
mid=(low+high)/2;
mmid=(high+mid)/2;
if(Fx(mid)>Fx(mmid))
high=mid;
else
low=mmid;
}
my=(mid+mmid)/2;
if(Fx(my)<y) printf("-1\n");
else
{
low=0,high=my;
while(high-low>ans)
{
mid=(low+high)/2;
if(Fx(mid)>y)
high=mid;
else
low=mid;
}
printf("%.6lf\n",mid);
}
}
return 0;
}