XMU 1125 越野车大赛 【三分】

1125: 越野车大赛

Time Limit: 500 MS  Memory Limit: 64 MB  Special Judge
Submit: 8  Solved: 4
[Submit][Status][Web Board]

Description

  TheBeet正在参加一场越野车大赛。比赛的场地如右图:
  共分三块,每一块地面的长宽均为N与M,但地表情况不同,越野车在这段路面上的最高速度也不同。
  蓝色线表示TheBeet可能的行车路线。
  比赛的要求是要求选手从比赛的场地左上角驾车至右下角。TheBeet想知道如果他在所有路段都以最快速度行驶(不考虑加速阶段),最快能在多少时间内完成比赛。

Input

  输入数据的第一行为两个正整数N M(N<=3000,M<=1000),表示一块路面的长和宽。
  第二行为三个正整数S1,S2,S3(0<S1,S2,S3<=100),从上至下依次表示各个路面上越野车的最高速度。

Output

  输出一个实数表示TheBeet最快能在多少时间内完成比赛。请输出一个尽可能精确的数字,控制误差在±0.000001的内。

Sample Input

30 10
2 5 3

Sample Output

13.7427361525

HINT

 

  如果你的输出和结果的相差在0.000001之内,则认为是正确答案。

 

Source

[Submit][Status][Web Board]

 

 

题目链接:

  http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1125

题目大意:

  比赛地分三块,每一块地面的长宽均为N与M,在1 2 3号地上的速度为S1,S2,S3。

  问从左上角到右下角的最小耗时。

题目思路:

  【三分】

  假设第一段到i,第二段到j,则t=sqrt(1.0*sqr(i)+sqr(m))/s1+sqrt(1.0*sqr(j-i)+sqr(m))/s2+sqrt(sqr(n-j)+sqr(m))/s3

  易知t为i,j的函数,且单调。所以两层三分答案。

  设区间l,r,取三等分点x1,x2的函数值f1,f2比较,若f1优则r=x2,否则l=x1

  直到区间间隔小于EPS停止。

  此时即为答案。

 

 1 /****************************************************
 2     
 3     Author : Coolxxx
 4     Copyright 2017 by Coolxxx. All rights reserved.
 5     BLOG : http://blog.csdn.net/u010568270
 6     
 7 ****************************************************/
 8 #include<bits/stdc++.h>
 9 #pragma comment(linker,"/STACK:1024000000,1024000000")
10 #define abs(a) ((a)>0?(a):(-(a)))
11 #define lowbit(a) (a&(-a))
12 #define sqr(a) ((a)*(a))
13 #define mem(a,b) memset(a,b,sizeof(a))
14 const double EPS=1e-8;
15 const int J=10000;
16 const int MOD=100000007;
17 const int MAX=0x7f7f7f7f;
18 const double PI=3.14159265358979323;
19 const int N=1004;
20 using namespace std;
21 typedef long long LL;
22 double anss;
23 LL aans;
24 int cas,cass;
25 int n,m,lll,ans;
26 double s1,s2,s3;
27 inline double cal(double i,double j)
28 {
29     return sqrt(1.0*sqr(i)+sqr(m))/s1+sqrt(1.0*sqr(j-i)+sqr(m))/s2+sqrt(sqr(n-j)+sqr(m))/s3;
30 }
31 int main()
32 {
33     #ifndef ONLINE_JUDGE
34 //    freopen("1.txt","r",stdin);
35 //    freopen("2.txt","w",stdout);
36     #endif
37     int i,j,k,l;
38     int x,y,z;
39 //    for(scanf("%d",&cass);cass;cass--)
40 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
41 //    while(~scanf("%s",s))
42     while(~scanf("%d",&n))
43     {
44         scanf("%d",&m);
45         scanf("%lf%lf%lf",&s1,&s2,&s3);
46         double xl,xr,yl,yr,x1,x2,y1,y2,f1,f2;
47         anss=1e20;
48         xl=0;xr=n;
49         while(xr-xl>EPS)
50         {
51             x1=(xl+xl+xr)/3.0;
52             x2=(xl+xr+xr)/3.0;
53             yl=x1;
54             yr=n;
55             while(yr-yl>EPS)
56             {
57                 y1=(yl+yl+yr)/3.0;
58                 y2=(yl+yr+yr)/3.0;
59                 f1=cal(x1,y1);
60                 f2=cal(x1,y2);
61                 if(f1<f2)
62                     yr=y2;
63                 else yl=y1;
64             }
65             anss=f1;
66             
67             yl=x2;
68             yr=n;
69             while(yr-yl>EPS)
70             {
71                 y1=(yl+yl+yr)/3.0;
72                 y2=(yl+yr+yr)/3.0;
73                 f1=cal(x2,y1);
74                 f2=cal(x2,y2);
75                 if(f1<f2)
76                     yr=y2;
77                 else yl=y1;
78             }
79             f1=anss;
80             if(f1<f2)
81                 xr=x2;
82             else xl=x1;
83         }
84         printf("%.10lf\n",anss);
85     }
86     return 0;
87 }
88 /*
89 //
90 
91 //
92 */
View Code

 

posted @ 2017-04-06 13:22  Cool639zhu  阅读(177)  评论(0编辑  收藏  举报