题目链接:

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

题意:

能开车,能步行,不过开车开一段距离后得修车,问到达目的地的最短时间;

思路:

AC代码:
/************************************************
┆ ┏┓   ┏┓ ┆
┆┏┛┻━━━┛┻┓ ┆
┆┃       ┃ ┆
┆┃   ━   ┃ ┆
┆┃ ┳┛ ┗┳ ┃ ┆
┆┃       ┃ ┆
┆┃   ┻   ┃ ┆
┆┗━┓   ┏━┛ ┆
┆  ┃   ┃  ┆      
┆  ┃   ┗━━━┓ ┆
┆  ┃  AC代马   ┣┓┆
┆  ┃    ┏┛┆
┆  ┗┓┓┏━┳┓┏┛ ┆
┆   ┃┫┫ ┃┫┫ ┆
┆   ┗┻┛ ┗┻┛ ┆
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e5+10;
const int maxn=(1<<8);
const double eps=1e-8; int main()
{
LL d,k,a,b,t,ans=0;
read(d);read(k);read(a);read(b);read(t); if(k*a+t<=k*b)
{
if(d%k==0)
{
ans=d/k*(k*a+t)-t;
}
else
{
if(d>=k){ans=d/k*(k*a+t)-t;ans=ans+min(d%k*b,t+d%k*a);}
else ans=d*a; }
}
else
{
ans=min(d,k)*a;
d=d-min(d,k);
ans=ans+d*b;
}
cout<<ans<<endl; return 0;
}

  

codeforces 702D D. Road to Post Office(数学)的更多相关文章

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

  2. Educational Codeforces Round 15 Road to Post Office

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

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

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

  6. cf702D Road to Post Office

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

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

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

  8. Codeforces 702D Road to Post Office(模拟 + 公式推导)

    题目链接:http://codeforces.com/problemset/problem/702/D 题意: 一个人要去邮局取东西,从家到达邮局的距离为 d, 它可以选择步行或者开车,车每走 k 公 ...

  9. CodeForces 702D Road to Post Office

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

随机推荐

  1. 解决mac osx下pip安装ipython权限的问题

    1 pip install ipython --user -U 下面是pip install gevent的错误提示, 又是 Operation not permitted …   1 2 3 4 5 ...

  2. Android -- 开机启动无界面后台程序

    简单的说,这是一个没有界面的后台运行的应用程序 而且,还有一功能:开机自启动,启动运行一个服务 程序结构非常简单,两个类,一个是service的扩展类,一个是BroadcastReceiver扩展类 ...

  3. 5.【nuxt起步】-swiper组件

    接下来是一个比较常用,也比较重要的组件 swiper,可以自行搜索 vue swiper,有很多开源组件,我这里就复用之前一个熟悉的, 1.新建component/banner.vue 刷新报错: 要 ...

  4. host dig nslookup bind

    这三个工具包含在yum install bind-utils -y dig -t mx|ns|A baidu.com qq.com dig -x 113,11.2.11 http://www.cnbl ...

  5. windows xp下mysql5.0安装

    安装注意要点: 1.不要安装在带有中文的安装路径 2.之前若有安装过mysql,请一定要卸载干净       MySQL安装的图解5.0.28 - CSDN

  6. ASP.NET MVC Filters 4种默认过滤器的使用【附示例】 数据库常见死锁原因及处理 .NET源码中的链表 多线程下C#如何保证线程安全? .net实现支付宝在线支付 彻头彻尾理解单例模式与多线程 App.Config详解及读写操作 判断客户端是iOS还是Android,判断是不是在微信浏览器打开

    ASP.NET MVC Filters 4种默认过滤器的使用[附示例]   过滤器(Filters)的出现使得我们可以在ASP.NET MVC程序里更好的控制浏览器请求过来的URL,不是每个请求都会响 ...

  7. Centos 安装Puppet

    环境说明: OS:CentOS 5.4 i386puppetmaster    192.168.0.12    hostname: puppetmaster.info.comclient       ...

  8. Spring里bean之间的循环依赖解决与源码解读

    通过前几节的分析,已经成功将bean实例化,但是大家一定要将bean的实例化和完成bean的创建区分开,bean的实例化仅仅是获得了bean的实例,该bean仍在继续创建之中,之后在该bean实例的基 ...

  9. caffe搭建--ubuntu标准平台的搭建

    http://caffe.berkeleyvision.org/install_apt.html Ubuntu Installation General dependencies sudo apt-g ...

  10. HDU 3308 LCIS (线段树&#183;单点更新&#183;区间合并)

    题意  给你一个数组  有更新值和查询两种操作  对于每次查询  输出相应区间的最长连续递增子序列的长度 基础的线段树区间合并  线段树维护三个值  相应区间的LCIS长度(lcis)  相应区间以左 ...