zoukankan      html  css  js  c++  java
  • CodeForces 700A As Fast As Possible

    要保证总时间最短,因为总时间计的是最后一个人到达的时间,也就是最后一个人要求尽快到达,也就是说我们要让最后一个人乘车时间尽量多。再仔细想想可以发现每个人的乘车时间和走路时间都是一样的。

    因此,可以二分每个人的乘车时间$m$,然后进行验证,如果发现某一个人的乘车时间不到$m$,那么$m$不可取,上界缩小;如果$m$可取,那么上界增大。

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #include<map>
    #include<set>
    #include<queue>
    #include<stack>
    #include<iostream>
    using namespace std;
    typedef long long LL;
    const double pi=acos(-1.0),eps=1e-8;
    void File()
    {
        freopen("D:\in.txt","r",stdin);
        freopen("D:\out.txt","w",stdout);
    }
    template <class T>
    inline void read(T &x)
    {
        char c = getchar(); x = 0;while(!isdigit(c)) c = getchar();
        while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar();  }
    }
    
    int n,L,v1,v2,k;
    
    bool check(double m)
    {
        double x=0; int p=n;
        while(1)
        {
            p=p-min(p,k); double t=(1.0*L-x)/v2;
            if(t<m) return 0; if(p==0) break;
            x=x+v1*m; double tmp=m*(v2-v1)/(v1+v2);
            x=x+tmp*v1;
        }
        return 1;
    }
    
    int main()
    {
        scanf("%d%d%d%d%d",&n,&L,&v1,&v2,&k);
        double left=0,right=1.0*L/v2,ans=0;
        int T=100;
        while(T--)
        {
            double m=(left+right)/2;
            if(check(m)) left=m,ans=m+(1.0*L-m*v2)/v1;
            else right=m;
        }
        printf("%.6lf
    ",ans);
        return 0;
    }
  • 相关阅读:
    Leetcode 1489找到最小生成树李关键边和伪关键边
    Leetcode 113 路径总和 II
    hdu 1223 还是畅通工程
    hdu 1087 Super Jumping! Jumping! Jumping!
    hdu 1008 Elevator
    hdu 1037 Keep on Truckin'
    湖工oj 1241 畅通工程
    湖工oj 1162 大武汉局域网
    hdu 2057 A + B Again
    poj 2236 Wireless Network
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5801972.html
Copyright © 2011-2022 走看看