zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 15_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
    Note

    In the first example Vasiliy needs to drive the first 2 kilometers on the car (in 2 seconds) and then to walk on foot 3 kilometers (in 12 seconds). So the answer equals to 14 seconds.

    In the second example Vasiliy needs to drive the first 2 kilometers on the car (in 2 seconds), then repair his car (in 5 seconds) and drive 2 kilometers more on the car (in 2 seconds). After that he needs to walk on foot 1 kilometer (in 4 seconds). So the answer equals to 13 seconds.

    题意:

    一个人 有一辆鸡公车,开k千米,会坏,然后需要t秒来修,然后车走1千米耗时为a秒,人走1千米耗时为b秒,问走d千米,最少耗时多少

    题解:

    这题直接分类讨论,模拟一下就行,不知道为什么在D题这个位置。

    详细看代码

     1 #include<bits/stdc++.h>
     2 #define F(i,a,b) for(int i=a;i<=b;++i)
     3 using namespace std;
     4 typedef long long ll;
     5 
     6 int main(){
     7     ll d,k,a,b,t,ans=0;
     8     scanf("%I64d%I64d%I64d%I64d%I64d",&d,&k,&a,&b,&t);
     9     if(d<=k){printf("%I64d
    ",d*a);return 0;}
    10     d-=k,ans+=k*a;
    11     if(d<=k){
    12         ll tpa=d*a+t;
    13         ll tpb=d*b;
    14         if(tpa<tpb)ans+=tpa;
    15         else ans+=tpb;
    16         printf("%I64d
    ",ans);
    17         return 0;
    18     }
    19     ll tpa=k*a+t,tpb=k*b;
    20     if(tpa<tpb){
    21         ll now=d/k;
    22         ans+=tpa*now;
    23         d%=k;
    24         if(d==0){printf("%I64d
    ",ans);return 0;}
    25     }else{
    26         ans+=d*b;
    27         printf("%I64d
    ",ans);
    28         return 0;
    29     }
    30     tpa=d*a+t;
    31     tpb=d*b;
    32     if(tpa<tpb)ans+=tpa;else ans+=tpb;
    33     printf("%I64d
    ",ans);
    34     return 0;
    35 }
    View Code
  • 相关阅读:
    冲刺五
    ubuntu安装utorrent
    struts2中properties属性
    Hadoop下的word count程序
    导入svn项目时eclipse崩溃
    Struts2 中jsp直接跳转到action
    用eclipse开发hadoop程序
    ubuntu下安装java
    【橙色警报】最新盗qq号方式,连我这个老鸟都一不小心被骗了
    在ubuntu上安装hadoop(书和官方文档结合的)
  • 原文地址:https://www.cnblogs.com/bin-gege/p/5720069.html
Copyright © 2011-2022 走看看