题目链接:

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('\n');
} 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;
}

  

codeforces 702D D. Road to Post Office(数学)的更多相关文章

  1. 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 standa ...

  2. Educational Codeforces Round 15 Road to Post Office

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

  3. 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 standa ...

  4. Codeforces 702 D Road to Post Office

    题目描述 Vasiliy has a car and he wants to get from home to the post office. The distance which he needs ...

  5. Codeforces 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 standa ...

  6. cf702D Road to Post Office

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

  7. D. Road to Post Office 解析(思維)

    Codeforce 702 D. Road to Post Office 解析(思維) 今天我們來看看CF702D 題目連結 題目 略,請直接看原題. 前言 原本想說會不會也是要列式子解或者二分搜,沒 ...

  8. Codeforces 702D Road to Post Office(模拟 + 公式推导)

    题目链接:http://codeforces.com/problemset/problem/702/D 题意: 一个人要去邮局取东西,从家到达邮局的距离为 d, 它可以选择步行或者开车,车每走 k 公 ...

  9. CodeForces 702D Road to Post Office

    答案的来源不外乎于3种情况: 纯粹走路,用时记为${t_1}$:纯粹乘车,用时记为${t_2}$:乘车一定距离,然后走路,用时记为${t_3}$. 但是${t_1}$显然不可能成为最优解. 前两个时间 ...

随机推荐

  1. [置顶] Android 应用内禁止截屏功能的实现

    截图介绍   Android的调试工具DDMS提供有截屏功能,很多软件也会有截屏功能,在做支付等安全类应用的时候,为了保证用户的资产和系统安全,往往会禁止应用内截屏,禁止之后,在此应用处于前台的情况下 ...

  2. linux删除空行操作:awk、grep、tr、sed

    如下:如何删除空行 shen\nshen\\n sen seh sehe she she 真正删除空行,可以使用vim: 通过命令模式删除空行.vim在命令模式下(在vim里输入英文字符:进入命令模式 ...

  3. mysql 安装配置及经常使用操作

    作为关系型数据库的一种,mysql因其占用内存小和开源等特性而兴起.以下简介下关于mysql配置和简单的操作. mysql配置 1.安装文件的下载 免安装版下载地址 :http://dev.mysql ...

  4. odoo生产物流

    odoo生产从raw materials location 自动消耗物料,产成品进入到finish productslocation. 而odoo自动产生的MO[manufacture Order], ...

  5. overflow滚动条样式设置,ie和webkit内核

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. Linux中du和df

    Linux运维过程中,常常发现du和df返回值不一样,偶尔会发现区别非常大. 特定情况下,可能df看到磁盘已满,可是du推断磁盘剩余空间非常大. 文件系统分配当中的一些磁盘块用来记录它自身的一些数据. ...

  7. 从头认识java-14.1 再次对照数组与容器

    这一章节我们再次深入的对照数组与容器. 数组与容器主要集中在三个方面:效率.类型.基础类型. 我们能够从三方面做出对照. 1.效率 这里的下来是指add和get 的速度 以下以add为例: packa ...

  8. Google Chrome的快捷键

    1.Ctrl + N 打开一个新窗口           &&            Alt + F4    关闭当前窗口 2.Ctrl + T 打开一个新的标签页 && ...

  9. Linux快捷键和vim快捷键

    系统下常用快捷键   ctrl+左右键      在单词之间跳转 Ctrl + a            光标移动到行首(ahead of line),相当于通常的Home键 Ctrl + e     ...

  10. 2016/08/18 select

    1.//得到select项的个数 2.jQuery.fn.size = function(){ 3. return jQuery(this).get(0).options.length; 4.} 5. ...