Codeforces 702 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 ddkilometers.
Vasiliy's car is not new — it breaks after driven every kk kilometers and Vasiliy needs tt seconds to repair it. After repairing his car Vasiliy can drive again (but after kk 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 aa seconds, to walk one kilometer on foot he needs bb seconds ( a<ba<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,td,k,a,b,t ( 1<=d<=10^{12}1<=d<=1012 ; 1<=k,a,b,t<=10^{6}1<=k,a,b,t<=106 ; a<ba<b ), where:
dd — the distance from home to the post office;
kk — the distance, which car is able to drive before breaking;
aa — the time, which Vasiliy spends to drive 1 kilometer on his car;
bb — the time, which Vasiliy spends to walk 1 kilometer on foot;
- tt — 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<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<vector>
#define ll long long
using namespace std;
ll cost,d,b,a,k,t,n;
int main(){
scanf("%lld%lld%lld%lld%lld",&d,&k,&a,&b,&t);
ll xl=(a-b)*k+t,tim=d/k+(d%k?:);
cost=min(b*d,d*a+(tim-)*t); if(k<=d){
if(xl>) cost=min(cost,b*d-t+xl);
else{
n=d/k;
cost=min(cost,xl*n+b*d-t);
}
} printf("%lld\n",cost);
return ;
}
Codeforces 702 D Road to Post Office的更多相关文章
- Educational Codeforces Round 15 Road to Post Office
Road to Post Office 题意: 一个人要从0走到d,可以坐车走k米,之后车就会坏,你可以修或不修,修要花t时间,坐车单位距离花费a时间,走路单位距离花费b时间,问到d的最短时间. 题解 ...
- Educational Codeforces Round 15_D. Road to Post Office
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...
- codeforces 702D D. Road to Post Office(数学)
题目链接: D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input ...
- D. Road to Post Office 解析(思維)
Codeforce 702 D. Road to Post Office 解析(思維) 今天我們來看看CF702D 題目連結 題目 略,請直接看原題. 前言 原本想說會不會也是要列式子解或者二分搜,沒 ...
- Codeforces Educational Codeforces Round 15 D. Road to Post Office
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Educational Codeforces Round 15 D. Road to Post Office 数学
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...
- cf702D Road to Post Office
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces 702D Road to Post Office(模拟 + 公式推导)
题目链接:http://codeforces.com/problemset/problem/702/D 题意: 一个人要去邮局取东西,从家到达邮局的距离为 d, 它可以选择步行或者开车,车每走 k 公 ...
- CodeForces 702D Road to Post Office
答案的来源不外乎于3种情况: 纯粹走路,用时记为${t_1}$:纯粹乘车,用时记为${t_2}$:乘车一定距离,然后走路,用时记为${t_3}$. 但是${t_1}$显然不可能成为最优解. 前两个时间 ...
随机推荐
- 如何实现加载DOM时执行js代码
有一些功能需求,需要在DOM载入时马上执行一些函数,但又不愿意仅为了这一个需求而引入整个JQuery库,于是就把jQuery的方法提取出来,单独使用了. 大家可以使用windows.onload事件, ...
- python3创建目录
感觉python3最好用的创建目录函数是os.makedirs,它可以设置在多级目录不存在时自动创建,已经存在也不抛出异常. import os os.makedirs('hello/hello1/h ...
- Oracle查询字段内容为非数字的记录
今天在一张3W多记录的表里查非数字的异常数据~数据库太水,记录一发,因为2.5使用人员误输入为2..5.... select t.routecardlist_id,trim(translate(RTR ...
- SpringMVC学习 -- ModelAndView , Model , ModelMap , Map 及 @SessionAttributes 的使用
输出模型数据: ModelAndView:处理方法返回值类型为 ModelAndView 时 , 其中包含视图和模型信息.方法体即可通过该对象添加模型数据 , 即 SpringMVC 会把 Model ...
- 关于hadoop: command not found的问题
问题: 昨天在安装完hadoop伪分布式之后,执行hadoop下的子项目--文字计数功能时出现该错误,然后今天执行 hadoop fs -ls命令时系统给出同样的错误提醒,经过查找资料,初步认为是ha ...
- (转)Git冲突:commit your changes or stash them before you can merge. 解决办法
用git pull来更新代码的时候,遇到了下面的问题: error: Your local changes to the following files would be overwritten by ...
- swt MouseAdapter
Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method ...
- (转)自动安装VIM插件
转自: http://xwz.me/wiki/doku.php?id=vim:plugins 我的插件列表 把下面GetLatestVimScripts.dat放进~/.vim/GetLatest/目 ...
- HDU1018 (斯特林公式)
Big Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- selenium自动化添加日志
于logging日志的介绍,主要有两大功能,一个是控制台的输出,一个是保存到本地文件 先封装logging模块,保存到common文件夹命名为logger.py,以便于调用,直接上代码 filenam ...