Three-point angle ....
NPY and shotTime
limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 236 Accepted Submission (s): 87
Problem Descriptionnpy is going to has a PE test. One of the test subjects is throwing the shot. The height of NPY is H meters. He can throw the shot at the speed of v0 m/s and at the height of exactly H meters. He wonders if he throws the shot at the best angle,how far can he throw? (The acceleration of gravity, G, is $9.8m/s^2$)
Inputthe first line contains a integer $T (T \leq 10000) $,which indicates the number of test cases.
The next T lines,each contains 2 integers $H (0 \leq H \leq 10000m) $,which means the height of Npy,and $v _0 (0 \leq v_0 \leq 10000M/S) $, which means the initial velocity.
Outputfor each query,print a real number X is rounded to 2 digits after the decimal point and a separate line. X indicates the farthest distance he can throw.
Sample Input
20 11 2
Sample Output
0.100.99HintIf The height of NPY is 0,and he throws the shot at the 45°angle, he can throw farthest.
Sourcebestcoder Round #22
/* ***********************************************author:ckbosscreated time:2014 December 13 Saturday 23:27 32 seconds file Name : c.cpp************************************************ * * #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <cstdlib> #include <vector># Include <queue> #include <set> #include <map> #include <cmath>using namespace Std;const double Eps=1e-6;const Double g=9.8;double h,v;double Distan (double degree) {double Vx=v*sin (degree);d ouble vy=v*cos (degree); Double time = (Vx+sqrt (vx*vx+2*g*h))/G;return Time*vy;} int main () {//freopen ("In.txt", "R", stdin); Freopen ("OUT.txt", "w", stdout), int t_t;scanf ("%d", &t_t), while (t_t--) {scanf ("%lf%lf", &h,&v);d ouble Low=0.,high=90.; Double Mid1,mid2,ans=0;while (Fabs (high-low) >=eps) {mid1= (Low*2+high)/3.; Mid2= (low+high*2)/3.; Double Len1=distan (MID1);d ouble Len2=distan (MID2); Ans=max (Ans,max (LEN1,LEN2)); if (len2+ePS>LEN1) Low=mid1;else High=mid2;} printf ("%.2lf\n", ans);} return 0;}
Hdoj 5144 NPY and shot simple physics