zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 15 D 数学推公式

    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.

    题意:d,k,a,b,t

    • d — the distance from home to the post office; 从家到邮局的距离
    • k — the distance, which car is able to drive before breaking;车最多能开k
    • 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.修车的速度

     求从家到达邮局的最小时间。

    题解:题目保证a<b 第一段肯定是开车的  特判处理

    之后的路程以k为分段 比较 修车-开车所花的时间( t+a*k)与这一段步行所花的时间(b*k) 取min

    最后不足k的一段x 所花的时间为 min(t+a*x,b*x); 求和ans输出.

     1 /******************************
     2 code by drizzle
     3 blog: www.cnblogs.com/hsd-/
     4 ^ ^    ^ ^
     5  O      O
     6 ******************************/
     7 //#include<bits/stdc++.h>
     8 #include<iostream>
     9 #include<cstring>
    10 #include<cstdio>
    11 #include<map>
    12 #include<algorithm>
    13 #include<queue>
    14 #define ll __int64
    15 using namespace std;
    16 ll d,k,a,b,t;
    17 int main()
    18 {
    19     scanf("%I64d %I64d %I64d %I64d %I64d",&d,&k,&a,&b,&t);
    20     if(d<=k)
    21     {
    22         printf("%I64d
    ",d*a);
    23         return 0;
    24     }
    25     ll ans=k*a;
    26     d-=k;
    27     ll exm=d/k;
    28     ll plu=d%k;
    29     ans=ans+exm*min(t+a*k,b*k);
    30     ans=ans+min(t+a*plu,b*plu);
    31     printf("%I64d
    ",ans);
    32     return 0;
    33 }
  • 相关阅读:
    Linux学习进阶路线图
    Ubuntu打开终端的方法三种
    Linux下显示IP地理位置信息的小工具-nali
    kail2 linux 安装vmware tools
    Ubuntu下apt-get命令详解
    Eclipse安卓开发环境
    纪念逝去的计算器之计算表达式结果
    今年暑假要AC
    结课博客作业
    第七次课程作业
  • 原文地址:https://www.cnblogs.com/hsd-/p/5748668.html
Copyright © 2011-2022 走看看