题意:假设鲍勃是点(0,0), 可以调整角度解决轨迹。帮助鲍勃摄水果在附近的树,并给出 一个点 x ,y 坐标,给出初速度。求从坐标原点以什么角度斜上抛运动可以达到那个点。
思路:根据以前所学物理学知识,写出运动轨迹方程,即:a=x*x*(9.8/(2*v*v)) 再根据二分法求出角度
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
double PI=acos(1.0)
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
double PI=acos(1.0)
int main()
{
double x,y,v,a,b,c,t,x1,x2;
int n;
cin>>n;
cout.precision(6);
while(n--)
{
cin>>x>>y>>v;
if(x==0&&y==0)
cout<<0<<endl;
else
{
a=x*x*(9.8/(2*v*v));
b=-1*x;
c=y+a;
t=b*b-4*a*c;
if(t<0)
cout<<-1<<endl;
else
{
x1=(-1*b-sqrt(t))/(2*a);
x2=(-1*b+sqrt(t))/(2*a);
if(x1>=0)
{
if(x2>=0)
x1=min(x1,x2);
cout << fixed << atan(x1) << endl;
}
else if(x2 >=0)
cout << fixed << atan(x2) << endl;
else
cout<<-1<<endl;
}
}
}
return 0;
}