zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 15 Road to Post Office

    Road to Post Office

    题意:

    一个人要从0走到d,可以坐车走k米,之后车就会坏,你可以修或不修,修要花t时间,坐车单位距离花费a时间,走路单位距离花费b时间,问到d的最短时间。

    题解:

    首先要分成k段,k段的总长是ovmod,每一段可以选择修车坐车或选择走路,(只有第一段的时候不用修车),最后在加上剩下的那些路的时间,剩下的是mod,(可以选择修车坐车或选择走路)最后min答案就好了。但其中还有一种情况要注意,就是前ovmod也可以选择坐车之后不修走着,所以这种要特殊处理下。

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    const int INF=0x3f3f3f3f;
    const ll LINF=0x3f3f3f3f3f3f3f3f;
    #define PU puts("");
    #define PI(A) cout<<A<<endl
    #define SI(N) cin>>N
    #define SII(N,M) cin>>N>>M
    #define cle(a,val) memset(a,(val),sizeof(a))
    #define rep(i,b) for(int i=0;i<(b);i++)
    #define Rep(i,a,b) for(int i=(a);i<=(b);i++)
    #define reRep(i,a,b) for(int i=(a);i>=(b);i--)
    #define dbg(x) cout <<#x<<" = "<<x<<endl
    #define PIar(a,n) rep(i,n)cout<<a[i]<<" ";cout<<endl;
    #define PIarr(a,n,m) rep(aa,n){rep(bb, m)cout<<a[aa][bb]<<" ";cout<<endl;}
    const double EPS= 1e-9 ;
    
    /*  /////////////////////////     C o d i n g  S p a c e     /////////////////////////  */
    
    const int MAXN= 1000 + 9 ;
    
    ll d,k,a,b,t;
    
    
    int main()
    {
        iostream::sync_with_stdio(false);
        cin.tie(0);cout.tie(0);
        while(cin>>d>>k>>a>>b>>t)
        {
            ll ans=0;
            if (d<=k)
            {
                cout<<min(d*a,d*b)<<endl;
                continue;
            }
            ll mod=d%k;
            ll ovmod=d/k*k;
            //后面的那种情况就是,选择坐车之后不修走着
            ans+=min(min(ovmod/k*t-t+ovmod*a,ovmod*b),(ovmod-k)*b+k*a);
            ans+=min(t+mod*a,mod*b);
            PI(ans);
        }
        return 0;
    }
  • 相关阅读:
    Realtime crowdsourcing
    maven 常用插件汇总
    fctix
    sencha extjs4 command tools sdk
    首次吃了一颗带奶糖味的消炎药,不知道管用不
    spring mvc3 example
    ubuntu ati driver DO NOT INSTALL recommand driver
    yet another js editor on windows support extjs
    how to use springsource tools suite maven3 on command
    ocr service
  • 原文地址:https://www.cnblogs.com/s1124yy/p/5720877.html
Copyright © 2011-2022 走看看