Toxophily 物理问题

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>
这道题非常简单,本质上就是解一个二次方程求最小值罢了。
由题目我们可以得到这:
x = v*cosa*t
y = vtsina - 1/2(g*t^2)
两个式子消去t得到 gt^2 tana^2 - 2v^2xtana + 2v^2 + gx^2 = 0
这是一元二次方程组,变量为tana,求最小值,也是角的最小值。
#include<iostream> #include<cmath> #include<stdio.h> using namespace std; #define p acos(-1.0) #define g 9.8 double x,y,v,t,Min=0,Max=p/2,a,b,c,t1,t2,q,e1,e2; int main() {      int n;      scanf("%d",&n);      while(n--)      {     scanf("%lf%lf%lf",&x,&y,&v);     a = g*x*x;     b = -2*(v*v*x);     c = 2*v*v*y+g*x*x;     q = b*b - 4*a*c;     t1 = (-b + (sqrt(q)))/(2*a);     t2 = (-b - (sqrt(q)))/(2*a);     e1 = atan(t1);     e2 = atan(t2);     if(e1>=Min&&e1<=Max&&e2>=Min&&e2<=Max)     {         if(e1 < e2)             printf("%.6lf\n",e1);         else             printf("%.6lf\n",e2);     }     else if(e1>=Min&&e1<=Max)     {        printf("%.6lf\n",e1);     }     else if(e2>=Min&&e2<=Max)     {         printf("%.6lf\n",e2);     }     else         printf("%d\n",-1);      }     return 0; }

你可能感兴趣的:(Toxophily 物理问题)