HDU 5144

 题意:在给定的高度和初速度,任意抛使得它水平距离最远。

题解:我们可以很容易的推出 length = v*cos(x)*( sqrt( 2.0*h*g + v*v*sin(x)*sin(x) ) + v*sin(x) ) / g; 然后对 [ 0, π/2 ] 之间的弧度三分查找(凸线图形一般用三分)

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 #include <math.h>
 5 #include <ctype.h>
 6 #include <map>
 7 #include <set>
 8 #include <string>
 9 #include <vector>
10 #include <queue>
11 #include <stack>
12 #include <list>
13 #include <algorithm>
14 #include <iostream>
15 #define PI acos( -1.0 )
16 using namespace std;
17 typedef pair<int,int> P;
18 typedef long long ll;
19 const double E = 1e-7;
20 
21 const double g = 9.8;
22 double h, v;
23 
24 double dis( double x )
25 {
26     double ans = v*cos(x)*( sqrt( 2.0*h*g + v*v*sin(x)*sin(x) ) + v*sin(x) ) / g;
27     return ans;
28 }
29 
30 int main()
31 {
32     int T;
33     scanf( "%d", &T );
34     while( T-- )
35     {
36         scanf( "%lf%lf", &h, &v );
37         double r, l;
38         double legth = 0;
39         r = PI / 2.0;
40         l = 0;
41         while( r-l > E )
42         {
43             double mid =  l + ( r-l ) / 3;
44             double midmid = r - ( r-l ) / 3;
45             double ans1 = dis( mid );
46             double ans2 = dis( midmid );
47             if( ans1 < ans2 ) {l = mid; legth = max( legth, ans2 ); }
48             else { r = midmid; legth = max( legth, ans1 ); }
49         }
50         printf( "%.2lf\n", legth );
51     }
52     return 0;
53 }
View Code

 

posted @ 2014-12-14 22:05  A_dan  阅读(158)  评论(0编辑  收藏  举报