题目描述

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

Vasiliy's car is not new — it breaks after driven every kk kilometers and Vasiliy needs tt seconds to repair it. After repairing his car Vasiliy can drive again (but after kk 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 aa seconds, to walk one kilometer on foot he needs bb seconds ( a<ba<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.

输入输出格式

输入格式:

The first line contains 5 positive integers d,k,a,b,td,k,a,b,t ( 1<=d<=10^{12}1<=d<=1012 ; 1<=k,a,b,t<=10^{6}1<=k,a,b,t<=106 ; a<ba<b ), where:

  • dd — the distance from home to the post office;

  • kk — the distance, which car is able to drive before breaking;

  • aa — the time, which Vasiliy spends to drive 1 kilometer on his car;

  • bb — the time, which Vasiliy spends to walk 1 kilometer on foot;

  • tt — the time, which Vasiliy spends to repair his car.

输出格式:

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

输入输出样例

输入样例#1:

5 2 1 4 10
输出样例#1:

14
输入样例#2:

5 2 1 4 5
输出样例#2:

13

说明

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.

小学数学题。。。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<vector>
#define ll long long
using namespace std;
ll cost,d,b,a,k,t,n;
int main(){
scanf("%lld%lld%lld%lld%lld",&d,&k,&a,&b,&t);
ll xl=(a-b)*k+t,tim=d/k+(d%k?:);
cost=min(b*d,d*a+(tim-)*t); if(k<=d){
if(xl>) cost=min(cost,b*d-t+xl);
else{
n=d/k;
cost=min(cost,xl*n+b*d-t);
}
} printf("%lld\n",cost);
return ;
}

Codeforces 702 D Road to Post Office的更多相关文章

  1. Educational Codeforces Round 15 Road to Post Office

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

  2. 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 ...

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

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

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

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

  7. cf702D Road to Post Office

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

  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. Consumer [分组背包]

    Consumer Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others) Total Subm ...

  2. windows10-seaslog安装笔记

    1.seasLog在windows下的安装 首先,要下载seasLog的dll文件,下载地址:http://pecl.php.net/package/SeasLog  选择对应你的系统和php版本的d ...

  3. js获取当前url地址参数中文乱码问题

    网上看了一些关于此问题的文章,都说的不清不楚,有些更是乱七八糟,完全没法看,故此找了一篇能用的,借鉴作为笔记. //首先获取到当前页面的地址栏信息 var url = window.location. ...

  4. AngularJS+BootStrap的一些插件

    插件网址:http://jquerypluginplus.com/ 树  1.angular-bootstrap-nav-tree http://jquerypluginplus.com/angula ...

  5. 随机洗牌算法Knuth Shuffle和错排公式

    Knuth随机洗牌算法:譬如现在有54张牌,如何洗牌才能保证随机性.可以这么考虑,从最末尾一张牌开始洗,对于每一张牌,编号在该牌前面的牌中任意一张选一张和当前牌进行交换,直至洗到第一张牌为止.参考代码 ...

  6. 【Atcoder】ARC083 D - Restoring Road Network

    [算法]图论,最短路? [题意]原图为无向连通图,现给定原图的最短路矩阵,求原图最小边权和,n<=300. [题解]要求最小边权和下,原图的所有边一定是所连两端点的最短路. 那么现在将所有最短路 ...

  7. 【Sqlite3】SQLITE3使用总结(转)

    原文转自 https://www.cnblogs.com/wenxp2006/archive/2012/06/04/2535169.html SQL语句操作 介绍如何用sqlite 执行标准 sql  ...

  8. 详解SHOW PROCESSLIST显示哪些线程正在运行列出的状态

    SHOW PROCESSLIST显示哪些线程正在运行.您也可以使用mysqladmin processlist语句得到此信息.如果您有SUPER权限,您可以看到所有线程.否则,您只能看到您自己的线程( ...

  9. 关于preempt_enable 和 preempt_disable 【转】

    转自:http://blog.chinaunix.net/uid-8478094-id-2031177.html 关于preempt_enable 和 preempt_disable 允许抢占和禁止抢 ...

  10. python--requests_html

    这个模块从名字上也能看出来,是专门用来解析html的,这个和requests的作者是同一人,非常牛逼的一位大佬. 大致读了一下源码,总共一个py文件(但是引用了其他的模块),加上注释总共才700多行, ...