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}$显然不可能成为最优解. 前两个时间 ...
随机推荐
- var result = eval('(' + data + ')');的学习
$.post("url", function(data) { //这里的function(data)这里的data是前端页面获取的后台的返回的数据: var result = ev ...
- oracle导入和导出和授权
导入数据库: imp demo@orcl file=d:/bak_1023.dmp full=y ignore=y 导出数据库: @orcl file=d:/bak_1023.dmpexp yhtj/ ...
- 转:A Painless Q-learning Tutorial (一个 Q-learning 算法的简明教程)
demo 参见 MDP DEMO 本文是对 http://mnemstudio.org/path-finding-q-learning-tutorial.htm 的翻译,共分两部分,第一部分为中文 ...
- Spring - IoC(3): Bean 实例的创建方式
创建一个 Bean 实例对象的方法通常有如下方式: 调用构造器创建 Bean 实例 调用静态工厂方法创建 Bean 实例 调用实例工厂方法创建 Bean 实例 使用构造器创建 Bean 实例 XML ...
- ecma 2018, javascript spread syntax behaves like Object.assign
as the subject. It is only supported in Chrome version 60+, so, first check the version, or just use ...
- 【Mysql优化】key和index区别
mysql的key和index多少有点令人迷惑,这实际上考察对数据库体系结构的了解的. 1).key 是数据库的物理结构,它包含两层意义,一是约束(偏重于约束和规范数据库的结构完整性),二是索引 ...
- linux知识复习1-dup dup2
#include <sys/stat.h> #include <string.h> #include <fcntl.h> #include <stdio.h& ...
- virtualbox网络相关
前言 Baidu/google了n多次, 效果不佳. 网上说的都是比较老的virtualbox版本,有的是默认就bridge方式(2.2.0前), 有的不是bridge方式的,是通过工具uml-uti ...
- js实现的联想输入
以前也写过一个jQuery的这种插件,但是很多地方根本不用jQuery,这个功能也有很多其它库支持,但是为了用这个功能而加载很多js插件,这样效率明显下降了很多,而且这个东西平时也很常用,所以一决心自 ...
- DRF的认证与权限功能
认证 1.全局配置 在setting.py进行配置. REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( # 'rest_framework. ...