cf702D 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 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的距离,可以走路也可以开车,走路时每走1单位长度用b时间,开车1单位长度用a时间,保证a<b。但是开车经过k的距离就会抛锚,要修t时间。可以弃车走完剩下的路,问最小时间。
a<b,所以坐车一定比走路优。显然车子的第一个k是不开白不开的。
考虑行进k单位长度,开车用ka+t,走路就是kb。原来以为只要比完看看哪个更优然后一直用下去就好了,结果一看样例1不对,明明能开两段只开了一段,而且更优
然后我就想啊,如果要开车,前几段的路程k时间都是ka+t,最后一段是ka,因为最后弃车就不修了,但是t是他给的,如果t和ka差很多,是不是不开完车子能走的路程而在走到k*某个i的时候停下来会更优呢
然后我就天真的以为这肯定是个单峰的然后要找到i
然后就写了三分。。
最后一看挖槽是贪心
说白了就三种情况:
一是全用ka+t
二是全用db
三是只用一段ka然后剩下的(d-k)b
玛德
感情我看的样例一恰好是第三种情况
艹艹艹艹艹艹艹艹艹艹艹艹艹艹艹艹这是我当时的心情艹艹艹艹艹艹艹艹艹艹艹艹艹艹艹艹艹艹艹艹
这里放的还是我的三分,虽然贪心也是一样的效果
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void write(LL a)
{
if (a<){printf("-");a=-a;}
if (a>=)write(a/);
putchar(a%+'');
}
inline void writeln(LL a){write(a);printf("\n");}
LL d,k,a,b,t,l,r;
inline LL calc(LL x)
{
return x*k*a+(x-)*t+(d-x*k)*b;
}
inline LL sanfen(LL l,LL r)
{
if (r==l)return calc(l);
if (r==l+)
{
LL a=calc(l);
LL b=calc(l+);
return min(a,b);
}
if (r==l+)
{
LL a=calc(l);
LL b=calc(l+);
LL c=calc(l+);
return min(min(a,b),c);
}
LL midl=l+(r-l)/;
LL midr=r-(r-l)/;
LL a=calc(l);
LL b=calc(midl);
LL c=calc(midr);
LL d=calc(r);
if (a<=b)return sanfen(l,midl);
if (b<=c)return sanfen(midl,midr);
return sanfen(midr,r);
}
int main()
{
d=read();k=read();a=read();b=read();t=read();
if(k>=d){printf("%lld\n",a*d);return ;}
l=;r=d/k;
LL ss=d*a+r*t;
printf("%lld\n",min(ss,sanfen(l,r)));
}
cf702D
cf702D Road to Post Office的更多相关文章
- D. Road to Post Office 解析(思維)
Codeforce 702 D. Road to Post Office 解析(思維) 今天我們來看看CF702D 題目連結 題目 略,請直接看原題. 前言 原本想說會不會也是要列式子解或者二分搜,沒 ...
- Educational Codeforces Round 15 Road to Post Office
Road to Post Office 题意: 一个人要从0走到d,可以坐车走k米,之后车就会坏,你可以修或不修,修要花t时间,坐车单位距离花费a时间,走路单位距离花费b时间,问到d的最短时间. 题解 ...
- 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 ...
- 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 ...
- 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 ...
- codeforce 702D Road to Post Office 物理计算路程题
http://codeforces.com/contest/702 题意:人到邮局去,距离d,汽车在出故障前能跑k,汽车1公里耗时a,人每公里耗时b,修理汽车时间t,问到达终点最短时间 思路:计算车和 ...
- CodeForces 702D Road to Post Office
答案的来源不外乎于3种情况: 纯粹走路,用时记为${t_1}$:纯粹乘车,用时记为${t_2}$:乘车一定距离,然后走路,用时记为${t_3}$. 但是${t_1}$显然不可能成为最优解. 前两个时间 ...
随机推荐
- Unity3D 游戏的碰撞
首先创建两个精灵,然后都绑定上碰撞方法(这个是在上一篇文章的基本上): 不过 要注意一点就是碰撞器需要挂一个重力组件,不然无效 所以添加了差不多就能够实现物体碰撞了: 接下来技术写代码,让碰撞的时候进 ...
- CentOS 5.4下的Memcache安装步骤(Linux+Nginx+PHP+Memcached)
原文链接:http://www.jb51.net/article/29668.htm
- winows8.1或winows7 64bit 安装Itunes 64bit 11.1.3 无法打开一直停止工作的解决办法
winows8.1或winows7 64bit 安装Itunes 64bit 11.1.3 无法打开一直停止工作的解决办法 系统环境变量里的Path追加 ;C:\program files (x86) ...
- jQuery 效果- 动画
jQuery animate() 方法允许您创建自定义的动画. jQuery 动画实例 jQuery jQuery 动画 - animate() 方法 jQuery animate() 方法用于创建自 ...
- jQuery 效果 - 淡入淡出
通过 jQuery,您可以实现元素的淡入淡出效果. 点击展示 淡入/淡出 面板 实例 jQuery fadeIn()演示 jQuery fadeIn() 方法. jQuery fadeOut()演示 ...
- 获取Host文件权限 注册表导入
Windows Registry Editor Version 5.00 ;取得文件修改权限 [HKEY_CLASSES_ROOT\*\shell\runas] @="管理员权限" ...
- html 5的localstorag
随着我们硬件技术的发展,浏览器本身的功能也愈发的完善,从之前的cookie到现在的本地缓存机制,再到web storage,在之前html4 的时候使用cookie具有一些明显的局限,如大小限制,co ...
- Debug your C# project more efficiently
I am a very beginner working with C# and Visual Studio 2013. When I debug my project, I always reope ...
- 一些javascript免费中文书籍
在这里谢谢那些无私的人~~这些内容来自这里:我只把js的链接粘到这里了~ 还有其它技术文档, 实在是太多了, 多的看都看不完!!! Google JavaScript 代码风格指南 Google JS ...
- 在CentOS 7中轻松安装Atomic应用(atomicapp)
sudo yum install docker atomic etcd kubernetes sudo systemctl enable docker.service sudo systemctl s ...