Educational Codeforces Round 15 D. Road to Post Office 数学
1 second
256 megabytes
standard input
standard output
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,步行的时间为B,求最少的时间到邮局;
思路:简单数学题;K千米如果开车+修理的时间小就选择车,否则就步行;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define esp 0.00000000001
const int N=3e3+,M=1e6+,inf=1e9+,mod=;
int main()
{
ll d,k,a,b,t;
scanf("%I64d%I64d%I64d%I64d%I64d",&d,&k,&a,&b,&t);
ll tc=t+k*a;
ll tw=k*b;
if(d<=k)
{
printf("%I64d\n",d*a);
return ;
}
ll ans=k*a;
d-=k;
ans+=(d/k)*min(tc,tw);
d=d%k;
ans+=min(d*b,t+a*d);
printf("%I64d\n",ans);
return ;
}
Educational Codeforces Round 15 D. Road to Post Office 数学的更多相关文章
- 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 Road to Post Office
Road to Post Office 题意: 一个人要从0走到d,可以坐车走k米,之后车就会坏,你可以修或不修,修要花t时间,坐车单位距离花费a时间,走路单位距离花费b时间,问到d的最短时间. 题解 ...
- Educational Codeforces Round 15 (A - E)
比赛链接:http://codeforces.com/contest/702 A. Maximum Increase A题求连续最长上升自序列. [暴力题] for一遍,前后比较就行了. #inclu ...
- Educational Codeforces Round 15 D 数学推公式
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Educational Codeforces Round 15 C. Cellular Network
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Educational Codeforces Round 15 A. Maximum Increase
A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 15 C. Cellular Network(二分)
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 15 C 二分
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 15 A dp
A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- 对 pthread 做的一个简陋封装
参考自 pthreadcc 库的 ThreadBase 类 用法:继承该类,重写 execute 方法,调用父类的 launchThread 方法启动线程 Thread.h // // Thread. ...
- (七)solr7之Terms组件的使用
(七)solr7之Terms组件的使用 Terms组件提供访问索引项的字段和每个词相匹配的文档数量. 这可以用于建立一个自动建议特性或任何其他的特性,而这个terms不是搜索或文档级别的水平.快速检索 ...
- SharePoint服务器端对象模型 之 对象模型概述(Part 1)
在一个传统的ASP.NET开发过程中,我们往往会把开发分为界面展现层.逻辑业务层和数据访问层这三个层面.作为一个应用开发平台,SharePoint是微软在直观的开发能力和自由的扩展能力之间,取到的一个 ...
- cocos2d-x-3.1rc0中找不到"extensions/ExtensionMacros.h"的问题
笔者导入UI编辑器的资源时,提示无法打开包括文件:“extensions/ExtensionMacros.h”: No such file or directory” 然后参考了3.0的一篇文章.得出 ...
- JavaScript基础深入之
JS的数值类型是分为两类:基本数据类型和引用数据类型. 基本类型占据的内存栈空间,引用类型被保存在堆空间.引用类型赋值的变量也是被保存在栈空间的,它的作用类似于电视遥控器,负责操作堆空间内指向的对象. ...
- 学习 《UNIX网络编程》
学习本书之前,为了了解C语言,先通读了<C程序设计语言>.但对C语言的理解.熟悉可能还是不足,所以在学习本书的过程中,遇到看不懂的C代码,还要去查询.思考. 本书一开始,我就遇到了问题,运 ...
- redis add 'vm.overcommit_memory = 1' to /etc/sysctl.conf
w root@well:/etc# vim sysctl.conf #kernel.domainname = example.com # # /etc/sysctl.conf - Configurat ...
- Java 注解入门
1.什么是注解 注解的语法: @注解名称; 注解的作用: 用来替代 xml 配置文件; 在 Servlet 3.0 中就可以使用注解来代替配置文件; 注解是由框架来读取使用的; 所有的注解都是 Ann ...
- PHP的文件下载
1.通过header头部下载文件 header("Content-length: ".filesize($filename)); //指定文件下载的大小 header(' ...
- 斯坦福大学Andrew Ng - 机器学习笔记(5) -- 支持向量机(SVM)
大概用了一个月,Andrew Ng老师的机器学习视频断断续续看完了,以下是个人学习笔记,入门级别,权当总结.笔记难免有遗漏和误解,欢迎讨论. 鸣谢:中国海洋大学黄海广博士提供课程视频和个人笔记,在此深 ...