Educational Codeforces Round 15 D 数学推公式
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.
题意:d,k,a,b,t
- d — the distance from home to the post office; 从家到邮局的距离
- k — the distance, which car is able to drive before breaking;车最多能开k
- 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.修车的速度
求从家到达邮局的最小时间。
题解:题目保证a<b 第一段肯定是开车的 特判处理
之后的路程以k为分段 比较 修车-开车所花的时间( t+a*k)与这一段步行所花的时间(b*k) 取min
最后不足k的一段x 所花的时间为 min(t+a*x,b*x); 求和ans输出.
/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#define ll __int64
using namespace std;
ll d,k,a,b,t;
int main()
{
scanf("%I64d %I64d %I64d %I64d %I64d",&d,&k,&a,&b,&t);
if(d<=k)
{
printf("%I64d\n",d*a);
return ;
}
ll ans=k*a;
d-=k;
ll exm=d/k;
ll plu=d%k;
ans=ans+exm*min(t+a*k,b*k);
ans=ans+min(t+a*plu,b*plu);
printf("%I64d\n",ans);
return ;
}
Educational Codeforces Round 15 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 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 ...
- Codeforces Educational Codeforces Round 15 E - Analysis of Pathes in Functional Graph
E. Analysis of Pathes in Functional Graph time limit per test 2 seconds memory limit per test 512 me ...
- 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 (A - E)
比赛链接:http://codeforces.com/contest/702 A. Maximum Increase A题求连续最长上升自序列. [暴力题] for一遍,前后比较就行了. #inclu ...
随机推荐
- WCF中常见的几种Host,承载WCF服务的方法
1:写在前面 我们都知道WCF在运行的时候必须自己提供宿主来承载服务.WCF 本身没有附带宿主,而是提供了一个 ServiceHost 的类,该类允许您在自己的应用程序中host WCF 服务.然后调 ...
- 从报错“无效操作,连接被关闭”探究Transaction的Timeout超时机制
1.报错如下:Invalid Operation the connection is closed,无效操作,连接被关闭.这个错误是并不是每次都报,只有在复杂操作.大事务的情况下才偶然报出来. sta ...
- Android ViewPager自动播放
在开发Android应用的过程中,ViewPager有时候需要自动播放的功能,今天就介绍一下自动播放功能的实现,直接上代码: // viewpager auto play private static ...
- C++质因式分解
分解质因数是将一个数差分成为几个质数相乘,本函数n初始取2 void prim(int m, int n) { if (m > n) { while (m%n) n++; m/=n; prim( ...
- Android模拟器配置选项说明
Memory Options是模拟器的运行内存大小,类比电脑内存大小,就是在设置->应用程序中,正在运行标签页下面显示的那个大小Internal storage是模拟器内置存储空间大小,用于存放 ...
- Quartz 2D--长方形和线条绘图
今天原本想模仿2048 游戏的. 但是在设计背景环境时,涉及到绘图的知识!于是就开始对绘图进行了一翻学习. 若想自己绘图必须 写自己的View(继承UICView):然后重写UIView 中的 dra ...
- ThinkPHP中Session用法详解
在ThinkPHP封装了Session类,用户可以直接使用,常用的方法有: Session::set(name, value):注册 session . Session::is_set(name):检 ...
- libimobiledevice安装步骤
https://github.com/libimobiledevice/libimobiledevice libimobiledevice安装指南,你还不知道libimobiledevice为何物,赶 ...
- php中ckeditor(Fckeditor)的配置方法
ckeditor 编辑器php正确配置方法 1. 下载安装 CKEditor: http://ckeditor.com/ 解压下载到的CKEditor放到网站的路径中即可 2. 下载安装 CKFind ...
- SQL Server 按某一字段分组 取 最大 (小)值所在行的数据
SQL Server 按某一字段分组 取 最大 (小)值所在行的数据 -- 按某一字段分组 取 最大 (小)值所在行的数据 -- (爱新觉罗.毓华(十八年风雨,守得冰山雪莲花开) 2007-10-23 ...