Codeforces 702D Road to Post Office(模拟 + 公式推导)
来源:互联网 发布:c语言编程器下载 编辑:程序博客网 时间:2024/05/01 18:35
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.
这个题其实蛮简单的,可惜当时我头脑不清醒,加上智障智和钰神被上一题搞得有点焦虑,所以没有AC==
#include <iostream>#include <cmath>#include <string.h>#include<string>#include <algorithm>#include <vector>#include<math.h>#include<set>#include<string.h>#include <stdio.h>#define ll long long int#define cla(a) memset(a,0,sizeof(a))using namespace std;int main(){ll k, a, e, r, p;while (cin >> k >> a >> e >> r >> p){ll ans = 0;if(k<=a){ ans = k*e;}else{if (a*e + p <= a*r){ans = (k / a)*(a*e + p)-p;ll la = k / a;la = k - a*la;if (la*e + p <= la*r){ans += la*e + p;}else{ans += la*r;}}else{ans = a*e;k -= a;ans += k*r;}}cout << ans << '\n';}return 0;}//by swust_t_p
- Codeforces 702D Road to Post Office(模拟 + 公式推导)
- codeforces-702D-Road to Post Office
- Codeforces 702D - Road to Post Office
- Codeforces Problem 702D Road to Post Office(分类讨论)
- CF 702D Road to Post Office
- Educational Codeforces Round 15 D. Road to Post Office
- CodeForces-702D Road to Post Office(初中数学脑洞题)
- Codeforces 702D Road to Post Office【捎带数学的思维题】
- Educational Codeforces Round 15 D. Road to Post Office (数学)
- Educational Codeforces Round 15 D Road to Post Office(分类讨论)
- CodeForces702D. Road to Post Office(二分or数学)
- Codeforces 599D Spongebob and Squares 【公式推导 暴力】
- CodeForces 34D Road Map
- Codeforces Gym100425 D. Toll Road
- CodeForces 828D High Road
- Codeforces Round #332 (Div. 2) D. Spongebob and Squares 公式推导
- coderforces 702DRoad to Post Office
- 3D 坐标变换 公式 推导
- Requests库学习笔记
- Agri-Net POJ
- [数学杂题 位运算] ZROI 2017 提高6 T1 异或统计
- [图解数据结构之Java实现](2) --- 线性表之链表实现
- P3851航运调度
- Codeforces 702D Road to Post Office(模拟 + 公式推导)
- 郑州集训DAY3笔记
- css学习-2017.10.7
- C++入门
- 2017.10.07【NOIP提高组】模拟赛B组 Heatwave 题解
- 【Sort】242. Valid Anagram
- 360加速球效果实现
- Html+JavaScript+百度地图api:GPS功能单点运动
- (POJ 1949)Chores DAG简单DP