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.
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题这个位置。
详细看代码
1 #include<bits/stdc++.h> 2 #define F(i,a,b) for(int i=a;i<=b;++i) 3 using namespace std; 4 typedef long long ll; 5 6 int main(){ 7 ll d,k,a,b,t,ans=0; 8 scanf("%I64d%I64d%I64d%I64d%I64d",&d,&k,&a,&b,&t); 9 if(d<=k){printf("%I64d\n",d*a);return 0;} 10 d-=k,ans+=k*a; 11 if(d<=k){ 12 ll tpa=d*a+t; 13 ll tpb=d*b; 14 if(tpa<tpb)ans+=tpa; 15 else ans+=tpb; 16 printf("%I64d\n",ans); 17 return 0; 18 } 19 ll tpa=k*a+t,tpb=k*b; 20 if(tpa<tpb){ 21 ll now=d/k; 22 ans+=tpa*now; 23 d%=k; 24 if(d==0){printf("%I64d\n",ans);return 0;} 25 }else{ 26 ans+=d*b; 27 printf("%I64d\n",ans); 28 return 0; 29 } 30 tpa=d*a+t; 31 tpb=d*b; 32 if(tpa<tpb)ans+=tpa;else ans+=tpb; 33 printf("%I64d\n",ans); 34 return 0; 35 }