Toxophily
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1092 Accepted Submission(s): 601
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.
We all like toxophily.
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?
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.
We all like toxophily.
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?
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.
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.
Technical Specification
1. T ≤ 100.
2. 0 ≤ x, y, v ≤ 10000.
Technical Specification
1. T ≤ 100.
2. 0 ≤ x, y, v ≤ 10000.
Output
For each test case, output the smallest answer rounded to six fractional digits on a separated line.
Output "-1", if there's no possible answer.
Please use radian as unit.
Output "-1", if there's no possible answer.
Please use radian as unit.
Sample Input
3 0.222018 23.901887 121.909183 39.096669 110.210922 20.270030 138.355025 2028.716904 25.079551
Sample Output
1.561582 -1 -1
Source
Recommend
lcy
题意: 题目给出了一个水果的二维位置,和一只箭的初始速度,箭可以随意调整角度,问箭在什么角度(最小的角度)可以射到水果。考虑箭的重力加速度。
意解: 运用物理学的速度公式和x,y上的路程公式求出一个一元二次方程来;具体看看代码吧!
AC代码:
题意: 题目给出了一个水果的二维位置,和一只箭的初始速度,箭可以随意调整角度,问箭在什么角度(最小的角度)可以射到水果。考虑箭的重力加速度。
意解: 运用物理学的速度公式和x,y上的路程公式求出一个一元二次方程来;具体看看代码吧!
AC代码:
/**
x=v * t * cos(a),y = v * t * sin(a) - g * (t ^ 2) / 2;
消去t,得:y = v * sin(a) * x / ( v * cos(a) ) - g * ( x ^ 2 / ( v ^ 2 * con(a) ^ 2 ) ) / 2;
最后得到:g * x ^ 2 tan(a) ^ 2 - 2 * v ^ 2 * x * tan(a) + 2 * v ^ 2 * y + g * x ^ 2 = 0;
转化为这种形式: a * x * x + b * x + c = 0; 就直接求出它的两个解,分类讨论下就行了。
再判断a的合法性就可以了;
**/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <cstdlib>
#include <algorithm>
#define ls u << 1
#define rs u << 1 | 1
#define lson l, mid, u << 1
#define rson mid + 1, r, u << 1 | 1
#define pi acos(-1.0)
using namespace std;
double solve()
{
double x,y,v,a,b,c,d,s1,s2;
scanf("%lf %lf %lf",&x,&y,&v);
a = 9.8 * x * x;
b = 2.0 * v * v * x;
c = 2.0 * v * v * y + 9.8 * x * x;
d = b * b - 4.0 * a * c;
s1 = (b + sqrt(d)) / (2.0 * a);
s2 = (b - sqrt(d)) / (2.0 * a);
s1 = atan(s1);
s2 = atan(s2);
if(s1 <= pi / 2.0 && s1 >= 0 && s2 <= pi / 2.0 && s2 >= 0 )
{
return s1 < s2 ? s1: s2;
}
else if(s1 <= pi / 2.0 && s1 >= 0)
{
return s1;
}
else if(s2 <= pi / 2.0 && s2 >= 0 )
{
return s2;
}
else return -1;
}
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int T;
scanf("%d",&T);
while(T--)
{
double res;
if(( res = solve() ) != -1) printf("%.6lf\n",res);
else puts("-1");
}
return 0;
}