Toxophily
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 76 Accepted Submission(s) : 37
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>
Source
The 4th Baidu Cup final
题目大意:一个人的射出箭初始速度一定,让你选择一个角度使恰好击中制定目标。若无法击中则输出-1.
解题思路:1随着角度的变化,在目标x的对应的y为先增大后减小,可以运用三分法进行迭代,最后求出近似解。
2直接用物理方法用三角函数表示出关系,直接用cmath的函数进行一次计算即可。
注意事项:三分法要判断是否能够打中目标
ps:用数学方法太容易了,只是推出公式可能acm中可欲不可求的。
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
const double g=9.8;
double x,y,v,s,s1,a,b;
int n;
scanf("%d",&n);
while(n--)
{
scanf("%lf%lf%lf",&x,&y,&v);
s=sqrt(x*x+y*y);
a=atan(y/x);
s1=v*v*(1-sin(a))/g/cos(a)/cos(a);
if(s1<s)printf("-1\n");
else
{
b=(asin(s*g*cos(a)*cos(a)/v/v+sin(a))-a)/2;
b=b+a;
printf("%lf\n",b);
}
}
}