Problem Description
The recreation center of WHU ACM Team has indoor billiards, Ping Pang, chess and bridge, toxophily, deluxe ballrooms KTV rooms, fishing, climbing, and so on.<br>We all like toxophily.<br><br>Bob is hooked on toxophily recently. Assume that Bob is at point (0,0) and he wants to shoot the fruits on a nearby tree. He can adjust the angle to fix the trajectory. Unfortunately, he always fails at that. Can you help him?<br><br>Now given the object's coordinates, please calculate the angle between the arrow and x-axis at Bob's point. Assume that g=9.8N/m. <br>
Input
The input consists of several test cases. The first line of input consists of an integer T, indicating the number of test cases. Each test case is on a separated line, and it consists three floating point numbers: x, y, v. x and y indicate the coordinate of the fruit. v is the arrow's exit speed.<br>Technical Specification<br><br>1. T ≤ 100.<br>2. 0 ≤ x, y, v ≤ 10000. <br>
Output
For each test case, output the smallest answer rounded to six fractional digits on a separated line.<br>Output "-1", if there's no possible answer.<br><br>Please use radian as unit. <br>
Sample Input
3<br>0.222018 23.901887 121.909183<br>39.096669 110.210922 20.270030<br>138.355025 2028.716904 25.079551<br>
Sample Output
1.561582<br>-1<br>-1<br>
题意:一个人射箭站在(0,0)有速度输入初速度v和目标坐标 求角度
具体的想法一开始就判断最大的角度使得剑能不能到大所需的目标高度
不能达到很happy直接输出-1能再求下角度,
这样问题转为求极值和二分求值~
角度和距离的关系
v*sin(s)*x/(v*cos(s))-4.9*x*x/(v*cos(s)*v*cos(s))//x为重力加速度
代码:
#include<iostream>
#include<math.h>
#include<iomanip>
#define g 9.8
#define pi acos(-1.0)
#include<math.h>
#include<iomanip>
#define g 9.8
#define pi acos(-1.0)
using namespace std;
double x,y,v;
double distance_y(double s)
{
return v*sin(s)*x/(v*cos(s))-4.9*x*x/(v*cos(s)*v*cos(s));
}
int main()
{
double mid1,mid2,first,dend,sum1,sum2;
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>x>>y>>v;
first=0;
dend=pi;
while(fabs(dend-first)>1e-8)
{
mid1=first+(dend-first)/3;
mid2=dend-(dend-first)/3;
sum1=distance_y(mid1);
sum2=distance_y(mid2);
if(sum1>sum2)
dend=mid2;
else
first=mid1;
}
if(distance_y(first)<y)
{
cout<<-1<<endl;
continue;
}
first=0;
while(fabs(dend-first)>1e-10)
{
mid1=(dend+first)/2;
sum1=distance_y(mid1);
if(sum1<y)
first=mid1;
else
dend=mid1;
}
cout<<fixed<<setprecision(6)<<dend<<endl;
}
}
double x,y,v;
double distance_y(double s)
{
return v*sin(s)*x/(v*cos(s))-4.9*x*x/(v*cos(s)*v*cos(s));
}
int main()
{
double mid1,mid2,first,dend,sum1,sum2;
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>x>>y>>v;
first=0;
dend=pi;
while(fabs(dend-first)>1e-8)
{
mid1=first+(dend-first)/3;
mid2=dend-(dend-first)/3;
sum1=distance_y(mid1);
sum2=distance_y(mid2);
if(sum1>sum2)
dend=mid2;
else
first=mid1;
}
if(distance_y(first)<y)
{
cout<<-1<<endl;
continue;
}
first=0;
while(fabs(dend-first)>1e-10)
{
mid1=(dend+first)/2;
sum1=distance_y(mid1);
if(sum1<y)
first=mid1;
else
dend=mid1;
}
cout<<fixed<<setprecision(6)<<dend<<endl;
}
}