coderforces 702DRoad to Post Office
来源:互联网 发布:淘宝上如何修改评价 编辑:程序博客网 时间:2024/05/22 16:42
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.
题意:求到邮局所需要的最短时间
#include <cstdio>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;typedef __int64 LL;int main(){ LL d,k,a,b,t; while(~scanf("%I64d%I64d%I64d%I64d%I64d",&d,&k,&a,&b,&t)) { LL T = 0; if(d <= k) { T = min(a*d,b*d); } else { T = min(a * k,b * k); if(a * k + t < b * k) { T += (a * k + t) * (d / k - 1); if(d % k) T += min(a * (d % k) + t , b * (d % k)); } else { T += b * (d - k); } } printf("%I64d\n",T); } return 0;}
- coderforces 702DRoad to Post Office
- codeforces-702D-Road to Post Office
- Codeforces 702D - Road to Post Office
- CF 702D Road to Post Office
- Codeforces Problem 702D Road to Post Office(分类讨论)
- Codeforces 702D Road to Post Office(模拟 + 公式推导)
- CodeForces-702D Road to Post Office(初中数学脑洞题)
- Codeforces 702D Road to Post Office【捎带数学的思维题】
- Post Office
- Post Office
- Post Office
- Post Office
- Educational Codeforces Round 15 D. Road to Post Office
- CodeForces702D. Road to Post Office(二分or数学)
- coderforces 702AMaximum Increase
- pku 1160 Post Office
- POJ 1160 Post Office
- pku 1160 Post Office
- druid配置数据库连接使用密文密码
- 在 Xcode 7 中安装 Alcatraz
- WebStorm license server破解
- How to Animate the Up-Button to Hamburger like in Gmail
- C语言的三种整型数据类
- coderforces 702DRoad to Post Office
- MyEclipse2014的体验增强-格式模板
- ios developer tiny share-20160815
- CSS3-transform
- PullToRefreshGridView添加头部
- 【算法专题】【搜索】【DFS】枚举全排列
- Little Endian, Big Endian, 网络字节序
- [HDU1160]-FatMouse's Speed
- UVA 10200 Prime Time