Educational Codeforces Round 15_D. Road to Post Office
1 second
256 megabytes
standard input
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.
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.
Print the minimal time after which Vasiliy will be able to reach the post office.
5 2 1 4 10
14
5 2 1 4 5
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.
题意:
一个人 有一辆鸡公车,开k千米,会坏,然后需要t秒来修,然后车走1千米耗时为a秒,人走1千米耗时为b秒,问走d千米,最少耗时多少
题解:
这题直接分类讨论,模拟一下就行,不知道为什么在D题这个位置。
详细看代码
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
typedef long long ll; int main(){
ll d,k,a,b,t,ans=;
scanf("%I64d%I64d%I64d%I64d%I64d",&d,&k,&a,&b,&t);
if(d<=k){printf("%I64d\n",d*a);return ;}
d-=k,ans+=k*a;
if(d<=k){
ll tpa=d*a+t;
ll tpb=d*b;
if(tpa<tpb)ans+=tpa;
else ans+=tpb;
printf("%I64d\n",ans);
return ;
}
ll tpa=k*a+t,tpb=k*b;
if(tpa<tpb){
ll now=d/k;
ans+=tpa*now;
d%=k;
if(d==){printf("%I64d\n",ans);return ;}
}else{
ans+=d*b;
printf("%I64d\n",ans);
return ;
}
tpa=d*a+t;
tpb=d*b;
if(tpa<tpb)ans+=tpa;else ans+=tpb;
printf("%I64d\n",ans);
return ;
}
Educational Codeforces Round 15_D. Road to Post Office的更多相关文章
- Educational Codeforces Round 15 Road to Post Office
Road to Post Office 题意: 一个人要从0走到d,可以坐车走k米,之后车就会坏,你可以修或不修,修要花t时间,坐车单位距离花费a时间,走路单位距离花费b时间,问到d的最短时间. 题解 ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [Educational Codeforces Round 16]B. Optimal Point on a Line
[Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
- Educational Codeforces Round 6 C. Pearls in a Row
Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
- Educational Codeforces Round 9
Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
随机推荐
- 找工作---操作系统常考知识点总结【PB】
1.进程是并发过程中程序的执行过程 2.进程的特征:结构特征.动态性.并发性.独立性.异步性 3.临界区指在每个进程中访问临界资源的那段代码 4,现在操作系统中申请资源的基本单位是进程,在CPU得到执 ...
- 【 转】 C/C++结构体和联合体的区别
联合体用途:使几个不同类型的变量共占一段内存(相互覆盖) 结构体是一种构造数据类型用途:把不同类型的数据组合成一个整体-------自定义数据类型 总结: 声明一个联合体: union abc { i ...
- Webform动态创建删除行及后台取值
开发过程中经常碰到许多不确定事项,所以有时需要动态生成新的记录,如图所示,点击新增时新增一条参考记录,点击删除时则删除该记录:第一步,创建一个表格,用hidden记录当前最大行数,添加时则只需复制模板 ...
- awstats 日志分析
/tmp/awstats/awstats.ezrydel.com.conf LogFile="/usr/local/apache/domlogs/ezrydel.com" php版 ...
- String类之endsWith方法--->检测该字符串以xx为结尾
endsWith(XX)方法是java内置类String类的一个内置方法,我们直接拿来用即可了,下边是api说明:检测该字符串以xx为结尾,结果返回布尔值 public class Demo { pu ...
- jQuery第六章
jQuery与Ajax应用 一.Ajax的优势和不足 1.Ajax的优势: (1)不需要插件支持:不需要任何浏览器插件就可以被绝大多数浏览器支持 (2)优秀的用户体验:能在不刷新整个页面的前提下更新数 ...
- hdu_5821_Ball(贪心)
题目链接:hdu_5821_Ball 题意: 给你序列A和序列B,依次给你m个区间,每次你可以交换区间内的任意数,问最后能不能将A变成B 题解: 比赛当时没想到,智商被压制 1001: 假设有4个红球 ...
- SSH 两个表全套增删改(运动员住宿管理)
0.创建如下oracle的命令 create table HOTALINFO ( HOTALID ) not null, HOTALNAME ) not null, HOTALADDRESS ) no ...
- 回车事件jquery
有时候,操作按钮需要回车键 直接上代码: //回车事件document.onkeydown = function (e) { var ev = document.all ? window.event ...
- Kettle启动及简单操作(1)
官方Hadoop配置 http://wiki.pentaho.com/display/BAD/Configuring+Pentaho+for+your+Hadoop+Distro+and+Versio ...