zoukankan      html  css  js  c++  java
  • CodeForces 702D Road to Post Office

    答案的来源不外乎于3种情况:

    纯粹走路,用时记为${t_1}$;纯粹乘车,用时记为${t_2}$;乘车一定距离,然后走路,用时记为${t_3}$。

    但是${t_1}$显然不可能成为最优解。

    前两个时间都挺好算的,${t_3}$算的时候要讨论一下。

    如果是$a*k+t>=b*k$,那么也就是说第一个$k$的距离开车,然后开始走路。

    如果是$a*k+t<b*k$,那么可以尝试着最后不到$k$的距离走路,前面的都开车。

    直接得出数学公式有点难度,因为最优解不会逃出${t_1}$,${t_2}$,${t_3}$,那么这个时候我们可以尝试着把他们都算出来,然后取一个最小值就可以了。

    #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();  }
    }
    
    LL d,k,a,b,t;
    
    int main()
    {
        scanf("%lld%lld%lld%lld%lld",&d,&k,&a,&b,&t);
        LL t1=b*d,t2,t3;
        if(d%k==0) t2=(d/k-1)*(a*k+t)+a*k;
        else t2=(d/k)*(a*k+t)+a*(d%k);
    
        if(a*k+t>=b*k)
        {
            if(d<=k) t3=a*d;
            else t3=a*k+(d-k)*b;
        }
        else
        {
            if(d%k==0) t3=(d/k-1)*(a*k+t)+a*k;
            else
            {
                if(d<=k) t3=a*d;
                else t3=(d/k-1)*(a*k+t)+a*k+(d%k)*b;
            }
        }
    
        printf("%lld
    ",min(t1,min(t2,t3)));
        return 0;
    }
  • 相关阅读:
    取得窗口大小和窗口位置兼容所有浏览器的js代码
    一个简单易用的导出Excel类
    如何快速启动chrome插件
    网页表单设计案例
    Ubuntu下的打包解包
    The source file is different from when the module was built. Would you like the debugger to use it anyway?
    FFisher分布
    kalman filter
    Group delay Matlab simulate
    24位位图格式解析
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5803761.html
Copyright © 2011-2022 走看看