D. Road to Post Office
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output 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.

Input

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.
Output

Print the minimal time after which Vasiliy will be able to reach the post office.

Examples
input
5 2 1 4 10
output
14
input
5 2 1 4 5
output
13
Note

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的更多相关文章

  1. D. Road to Post Office 解析(思維)

    Codeforce 702 D. Road to Post Office 解析(思維) 今天我們來看看CF702D 題目連結 題目 略,請直接看原題. 前言 原本想說會不會也是要列式子解或者二分搜,沒 ...

  2. Educational Codeforces Round 15 Road to Post Office

    Road to Post Office 题意: 一个人要从0走到d,可以坐车走k米,之后车就会坏,你可以修或不修,修要花t时间,坐车单位距离花费a时间,走路单位距离花费b时间,问到d的最短时间. 题解 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. codeforce 702D Road to Post Office 物理计算路程题

    http://codeforces.com/contest/702 题意:人到邮局去,距离d,汽车在出故障前能跑k,汽车1公里耗时a,人每公里耗时b,修理汽车时间t,问到达终点最短时间 思路:计算车和 ...

  9. CodeForces 702D Road to Post Office

    答案的来源不外乎于3种情况: 纯粹走路,用时记为${t_1}$:纯粹乘车,用时记为${t_2}$:乘车一定距离,然后走路,用时记为${t_3}$. 但是${t_1}$显然不可能成为最优解. 前两个时间 ...

随机推荐

  1. 认识k_BackingField【转】

    事情从Json的序列化和反序列化说起. 在C#2.0的项目中,以前经常使用Json.Net实现序列化和反序列化.后来从c#3.0中开始使用新增的DataContractJsonSerializer进行 ...

  2. 在DataTable中更新、删除数据

    /*在DataTable中选择记录*/            /* 向DataTable中插入记录如上,更新和删除如下:             * ----但是在更新和删除前,首先要找出要更新和删除 ...

  3. SlidingMenu侧换菜单的导入

    对于Adt-22.3有一种使用SlidingMenu(侧滑菜单的方式),直接加你放到lib文件夹下

  4. Oracle数据导入导出imp/exp命令总结

    racle数据导入导出imp/exp就相当于oracle数据还原与备份.exp命令可以把数据从远程数据库服务器导出到本地的dmp文件,imp命令可以把dmp文件从本地导入到远处的数据库服务器中. 利用 ...

  5. javascript基础学习(十)

    javascript之数组 学习要点: 数组的介绍 定义数组 数组元素 数组的方法 一.数组的介绍 数组中的元素类型可以是数字型.字符串型.布尔型等,甚至也可以是一个数组. 二.定义数组 1.通过数组 ...

  6. javascript基础学习(六)

    javascript之对象 学习要点: 对象的属性和方法 对象的原型 一.对象 对象其实就是一种引用类型,而对象的值就是引用对象的实例. 二.创建对象 在javascript中有两种对象,一种是系统内 ...

  7. ktv

    自制KTV点歌系统经验 Windows Media Player控件播放       Windows Media Player控件的简单使用 1.播放一首歌曲的方法 Windows Media Pla ...

  8. linux指令备份

    ls -a 显示隐藏文件 cd 回到当前用户的目录 /home/ubuntu touch 创建文件 cat Hello.javamore/less Hello.java分页显示 grep root / ...

  9. Vijos1675 NOI2005 聪聪和可可 记忆化搜索

    简单题,结果因为理解错题意懵逼了好久…… moveTo[x][y]表示聪聪在节点x,可可在节点y时,聪聪下一步应到达哪一个节点 dp[x][y]表示聪聪在节点x,可可在节点y,且轮到可可行动时,所需时 ...

  10. CPU与外设传送数据方式

    7.2 CPU与外设之间数据传送的方式 在微型计算机系统中,CPU与外设之间的数据传送方式主要有程序传送方式.中断传送方式和直接存储器存取(DMA)传送方式,分别介绍如下.     7.2.1 程序传 ...