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;
    }
    

      

  • 相关阅读:
    [更新]一份包含: 采用RSA JWT(Json Web Token, RSA加密)的OAUTH2.0,HTTP BASIC,本地数据库验证,Windows域验证,单点登录的Spring Security配置文件
    fstab文件详解
    Struts2与Spring的Maven依赖冲突
    maven正确的集成命令-U -B 等
    CentOS6安装Jenkins
    CentOS6下Jenkins连接Git服务器出错的问题
    GitLab备份的创建与恢复
    开发App到上架应用市场需要经历什么?
    阅读笔记:A Few useful things to Know About machine Learning
    Feature Tools 简介
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5720287.html
Copyright © 2011-2022 走看看