Educational Codeforces Round 15 D Road to Post Office(分类讨论)
2016-12-02 16:59
429 查看
思路:由于车的速度肯定大于人的,那么第一段肯定是开车最优,然后分三种情况讨论,分别是剩下的都走路,一直开车到最后一段<k的时候走路,或者全程开车
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
Output
Input
Output
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.
#include<bits/stdc++.h> using namespace std; #define LL long long LL d,k,a,b,t; int main() { LL ans = 0; scanf("%lld%lld%lld%lld%lld",&d,&k,&a,&b,&t); LL last = d-k; if(last<=0)printf("%lld\n",d*a); else { d = last; ans+=k*a; LL t1 = d*b; //剩下的路程全部走路 LL t2 = (d/k)*k*a+(d/k)*t+(d-(d/k)*k)*b; //剩下的路程开车到小于k走路 LL t3 = d*a+((d/k)+1)*t; //一直开车 ans+=min(t1,min(t2,t3)); printf("%lld\n",ans); } }
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.
相关文章推荐
- 新增和修改存储过程语句
- 音乐播放器应用代码实现
- Vi指令,随时追加
- Google C++单元测试框架GoogleTest---AdvancedGuide(译文)下
- u-blox gps 串口驱动安装恢复解决方案
- RecyclerView的Item点击事件,增加删除Item瀑布流动画效果,长按拖动Item,RecyclerView复杂布局、实现新闻频道选择器
- 三数之和
- android进程间通信
- java自定义线程池--ThreadPoolExecutors
- 编码中的setCharacterEncoding 理解
- angular js ng-route 路由简单实例
- [鸟哥linux视频教程整理]03_02_Linux文件管理类命令及bash特性详解
- Educational Codeforces Round 15 C Cellular Network(二分)
- Python Email
- Android最实用TextView文字逐个打出效果
- 【地图API】地址录入时如何获得准确的经纬度?淘宝收货地址详解
- Yii2 之 富文本编辑器
- 小部件
- 近一年一些小坑
- ros 与 sony ps3joy