Educational Codeforces Round 15_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 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.
InputThe 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.
Examples input5 2 1 4 10output
14input
5 2 1 4 5output
13Note
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=0; scanf("%I64d%I64d%I64d%I64d%I64d",&d,&k,&a,&b,&t); if(d<=k){printf("%I64d\n",d*a);return 0;} 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 0; } ll tpa=k*a+t,tpb=k*b; if(tpa<tpb){ ll now=d/k; ans+=tpa*now; d%=k; if(d==0){printf("%I64d\n",ans);return 0;} }else{ ans+=d*b; printf("%I64d\n",ans); return 0; } tpa=d*a+t; tpb=d*b; if(tpa<tpb)ans+=tpa;else ans+=tpb; printf("%I64d\n",ans); return 0; }View Code
- Educational Codeforces Round 15 D. Road to Post Office
- Educational Codeforces Round 15 D Road to Post Office(分类讨论)
- Educational Codeforces Round 15 D. Road to Post Office (数学)
- Educational Codeforces Round 15 D. Road to Post Office 数学
- Educational Codeforces Round 15--AMaximum Increase--求最长上升数列的长度
- Codeforces 702 (Educational Codeforces Round 15) A~E
- Educational Codeforces Round 15(简单题)
- Educational Codeforces Round 15 B. Powers of Two
- 【最长递增子序列+(不下降)二分栈】Educational Codeforces Round 15
- 【解题报告】Educational Codeforces Round 15
- Educational Codeforces Round 15 Analysis of Pathes in Functional Graph rmq 变形
- Educational Codeforces Round 15
- Educational Codeforces Round 15 D 数学推导
- Educational Codeforces Round 4 C. Replace To Make Regular Bracket Sequence 栈
- Educational Codeforces Round 15, problem: (B) Powers of Two
- Educational Codeforces Round 15_B. Powers of Two
- Educational Codeforces Round 15
- Educational Codeforces Round 15
- Educational Codeforces Round 15 套题
- Educational Codeforces Round 15 E 树上倍增 RMQ思想