HDU 1004 Toxophily

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.
 

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.
 

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.
 

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
简单题意:射箭问题,抛体运动
解题思路:通过物理公式推导结果,直接计算
AC代码:
#include #include #include using namespace std; int main() { //ifstream cin("1004.txt"); int t ; double x , y , v , T , a , b , c ,angle ; double g = 9.8 ; cin >> t; while( t -- ) { cin >> x >> y >> v ; if(x == 0 && y == 0) printf("0\n"); else if(x == 0 && y > 0) printf("90\n"); else { a = g * pow(x,2) / (2*pow(v,2)); b = -x ;  c = g * pow(x,2) / (2 * pow(v , 2)) + y ; T = b * b - 4 * a * c; if(T < 0) printf("-1\n"); if(T == 0){ angle = - b / (2 * a) ; printf("%.6f\n",angle) ; } else  { double m , n , p; m = (-b + pow(T , 1.0/2))/(2 * a); if(m >= 0) angle = atan(m) ; n = (-b - pow(T , 1.0/2))/(2 * a); if(n >= 0){ p = atan(n); if(p < angle) angle = p ; printf("%.6f\n",angle) ; } if(m < 0 && n < 0) printf("-1\n"); } } } return 0; }

你可能感兴趣的:(HDU 1004 Toxophily)