zoukankan      html  css  js  c++  java
  • codeforces 702D D. Road to Post Office(数学)

    题目链接:

    D. Road to Post Office

    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d kilometers.

    Vasiliy's car is not new — it breaks after driven every k kilometers and Vasiliy needs t seconds to repair it. After repairing his car Vasiliy can drive again (but after k kilometers it will break again, and so on). In the beginning of the trip the car is just from repair station.

    To drive one kilometer on car Vasiliy spends a seconds, to walk one kilometer on foot he needs b seconds (a < b).

    Your task is to find minimal time after which Vasiliy will be able to reach the post office. Consider that in every moment of time Vasiliy can left his car and start to go on foot.

    Input

    The first line contains 5 positive integers d, k, a, b, t (1 ≤ d ≤ 1012; 1 ≤ k, a, b, t ≤ 106; a < b), where:

    • d — the distance from home to the post office;
    • k — the distance, which car is able to drive before breaking;
    • a — the time, which Vasiliy spends to drive 1 kilometer on his car;
    • b — the time, which Vasiliy spends to walk 1 kilometer on foot;
    • t — the time, which Vasiliy spends to repair his car.
    Output

    Print the minimal time after which Vasiliy will be able to reach the post office.

    Examples
    input
    5 2 1 4 10
    output
    14
    input
    5 2 1 4 5
    output
    13

    题意:

    能开车,能步行,不过开车开一段距离后得修车,问到达目的地的最短时间;

    思路:

    AC代码:

    /************************************************ 
    ┆  ┏┓   ┏┓ ┆    
    ┆┏┛┻━━━┛┻┓ ┆ 
    ┆┃       ┃ ┆ 
    ┆┃   ━   ┃ ┆ 
    ┆┃ ┳┛ ┗┳ ┃ ┆ 
    ┆┃       ┃ ┆  
    ┆┃   ┻   ┃ ┆ 
    ┆┗━┓    ┏━┛ ┆ 
    ┆  ┃    ┃  ┆       
    ┆  ┃    ┗━━━┓ ┆ 
    ┆  ┃  AC代马   ┣┓┆ 
    ┆  ┃           ┏┛┆ 
    ┆  ┗┓┓┏━┳┓┏┛ ┆ 
    ┆   ┃┫┫ ┃┫┫ ┆ 
    ┆   ┗┻┛ ┗┻┛ ┆       
    ************************************************ */  
    
    
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <bits/stdc++.h>
    #include <stack>
    
    using namespace std;
    
    #define For(i,j,n) for(int i=j;i<=n;i++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
    
    typedef  long long LL;
    
    template<class T> void read(T&num) {
        char CH; bool F=false;
        for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
        for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
        F && (num=-num);
    }
    int stk[70], tp;
    template<class T> inline void print(T p) {
        if(!p) { puts("0"); return; }
        while(p) stk[++ tp] = p%10, p/=10;
        while(tp) putchar(stk[tp--] + '0');
        putchar('
    ');
    }
    
    const LL mod=1e9+7;
    const double PI=acos(-1.0);
    const int inf=1e9;
    const int N=1e5+10;
    const int maxn=(1<<8);
    const double eps=1e-8;
    
    
    
    int main()
    {       
            LL d,k,a,b,t,ans=0;
            read(d);read(k);read(a);read(b);read(t);
            
            if(k*a+t<=k*b)
            {
                if(d%k==0)
                {
                    ans=d/k*(k*a+t)-t;
                }
                else 
                {
                    if(d>=k){ans=d/k*(k*a+t)-t;ans=ans+min(d%k*b,t+d%k*a);}
                    else ans=d*a;
                    
                }
            }
            else 
            {
                ans=min(d,k)*a;
                d=d-min(d,k);
                ans=ans+d*b;
            }
            cout<<ans<<endl;
    
            return 0;
    }
    

      

  • 相关阅读:
    【uva 1442】Cav(算法效率)
    【uva 10600】ACM Contest and Blackout(图论--次小生成树 模版题)
    【bzoj2429】[HAOI2006]聪明的猴子(图论--最小瓶颈生成树 模版题)
    【uva 534】Frogger(图论--最小瓶颈路 模版题)
    【poj 1988】Cube Stacking(图论--带权并查集)
    【uva 12174】Shuffle(算法效率--滑动窗口)
    关于最小生成树 Kruskal 和 Prim 的简述(图论)
    2019牛客暑期多校训练营(第五场) maximum clique 1
    左偏树/可并堆 学习笔记
    树的计数 Prüfer编码与Cayley公式 学习笔记
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5720287.html
Copyright © 2011-2022 走看看