C - Little Jumper (三分)

题目链接:https://cn.vjudge.net/contest/281961#problem/C

题目大意:青蛙能从一个点跳到第三个点,如图,需要跳两次。问整个过程的最大起跳速度中的最小的。

具体思路:三分寻找最大值,具体证明:https://blog.csdn.net/thearcticocean/article/details/51533065

AC代码:

 1 #include<iostream>
 2 #include<stack>
 3 #include<stdio.h>
 4 #include<cstring>
 5 #include<string>
 6 #include<cmath>
 7 #include<queue>
 8 #include<algorithm>
 9 using namespace std;
10 # define ll long long
11 const int maxn = 2e5+50000;
12 const int maxm = 1e6+100;
13 const double eps=1e-15;
14 double b1,t1,b2,t2,l,ds,df,g;
15 double cal(double L,double S,double T,double B)
16 {
17     double h=S-S*S/L;
18     if(h-T>eps)
19     {
20         double xx=g*S*(L-S)/2/T;
21         double yy=xx/S/S*(T+0.5*g*S*S/xx)*(T+0.5*g*S*S/xx);
22         return sqrt(xx+yy);
23     }
24     if(h-B<-eps)
25     {
26         double xx=g*S*(L-S)/2/B;
27         double yy=xx/S/S*(B+0.5*g*S*S/xx)*(B+0.5*g*S*S/xx);
28         return sqrt(xx+yy);
29     }
30     return sqrt(g*L);
31 }
32 double get(double x)
33 {
34     double v1=cal(x+ds,ds,t1,b1),v2=cal(l-x+df,df,t2,b2);
35     return v1-v2>eps?v1:v2;
36 }
37 int main()
38 {
39     while(~scanf("%lf %lf",&b1,&t1))
40     {
41         scanf("%lf %lf %lf %lf %lf %lf",&b2,&t2,&l,&ds,&df,&g);
42         double lt=0,rt=l,mid1,mid2;
43         double y1,y2;
44         int c=0;
45         while(rt-lt>eps&&c++<100)
46         {
47             mid1=lt+(rt-lt)/3;
48             mid2=rt-(rt-lt)/3;
49             y1=get(mid1);
50             y2=get(mid2);
51             if(y1<y2)
52                 rt=mid2;
53             else
54                 lt=mid1;
55         }
56         printf("%.6lf\n",get(lt));
57     }
58     return 0;
59 }

 

posted @ 2019-02-09 17:01  Let_Life_Stop  阅读(163)  评论(0编辑  收藏  举报