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 ...
随机推荐
- 数据库还原失败System.Data.SqlClient.SqlError: 无法执行 BACKUP LOG,因为当前没有数据库备份
结尾日志的问题 还原选择中去掉结尾日志就可以了 转载自:http://blog.csdn.net/aojiancc2/article/details/46316451
- caffe编译出现的新错误
1.include/caffe/blob.hpp:9:34: fatal error: caffe/proto/caffe.pb.h: No such file or directory #inclu ...
- 超链接解决头部fixed问题
///////////超链接解决头部fixed问题 $('a[href*=#]').click(function () { var top1 = $(".header").heig ...
- 【第四篇】Volley修改之GsonRequest
json解析工具类的引入,这里引用lite马天宇的解析json的工具类: public class GsonImpl extends Json { private Gson gson = new Gs ...
- Linux使用rsync客户端与服务端同步目录进行备份
一.服务端设置 1. 修改 server 端配置 # vi /etc/rsyncd.conf 修改: uid = nobody # 该选项指定当该模块传输文件时守护进程应该具有的uid.默认值为&qu ...
- Directed Roads
Directed Roads 题目链接:http://codeforces.com/contest/711/problem/D dfs 刚开始的时候想歪了,以为同一个连通区域会有多个环,实际上每个点的 ...
- Ubuntu系统上安装搜狗拼音输入法sogou
1. 首先在百度搜索搜狗拼音输入法Linux就能看到它的官网:http://pinyin.sogou.com/linux/ 下载后直接安装.安装成功后在控制台输入 im-config 如果选中的是fc ...
- 第九十七节,使用JavaScript
使用JavaScript 学习要点: 1.创建一张HTML页面 2.<Script>标签解析 3.JS代码嵌入的一些问题 一.创建一张HTML页面 因为JavaScript是嵌套在html ...
- JQuery:以name为条件查找
例如:$(":input[name='keleyi']") 表示查找的是name为keleyi的表单. var a=$(t).prev(":input[name='dis ...
- Objetive-C initialize研究
initialize执行时机 在向一个类执行实例方法或者类方法(除了initialize和load方法之外)的时候,触发initialize方法,因此如果一个类你没有使用的时候,是 ...