答案的来源不外乎于3种情况:

纯粹走路,用时记为${t_1}$;纯粹乘车,用时记为${t_2}$;乘车一定距离,然后走路,用时记为${t_3}$。

但是${t_1}$显然不可能成为最优解。

前两个时间都挺好算的,${t_3}$算的时候要讨论一下。

如果是$a*k+t>=b*k$,那么也就是说第一个$k$的距离开车,然后开始走路。

如果是$a*k+t<b*k$,那么可以尝试着最后不到$k$的距离走路,前面的都开车。

直接得出数学公式有点难度,因为最优解不会逃出${t_1}$,${t_2}$,${t_3}$,那么这个时候我们可以尝试着把他们都算出来,然后取一个最小值就可以了。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar(); x = ;while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} LL d,k,a,b,t; int main()
{
scanf("%lld%lld%lld%lld%lld",&d,&k,&a,&b,&t);
LL t1=b*d,t2,t3;
if(d%k==) t2=(d/k-)*(a*k+t)+a*k;
else t2=(d/k)*(a*k+t)+a*(d%k); if(a*k+t>=b*k)
{
if(d<=k) t3=a*d;
else t3=a*k+(d-k)*b;
}
else
{
if(d%k==) t3=(d/k-)*(a*k+t)+a*k;
else
{
if(d<=k) t3=a*d;
else t3=(d/k-)*(a*k+t)+a*k+(d%k)*b;
}
} printf("%lld\n",min(t1,min(t2,t3)));
return ;
}

CodeForces 702D Road to Post Office的更多相关文章

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

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

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

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

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

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

  5. Educational Codeforces Round 15 Road to Post Office

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

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

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

  8. cf702D Road to Post Office

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

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

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

随机推荐

  1. 【CSS学习笔记】超链接标签

    有些网址后面为什么是#? 比如,href="http://www.xxx.com/index.html/#q2"标示网页index.html的q2位置处,浏览器读取这个URL后,会 ...

  2. Activity和Fragment之间解耦

    看鸿洋博客:http://blog.csdn.net/lmj623565791/article/details/42628537,整理下一些关键点 public class ContentFragme ...

  3. svn问题(队列)

    svn执行clean up命令时报错"Previous operation has not finished; run 'cleanup' if it was interrupted&quo ...

  4. 学习Sass(一)

    一.什么是sass? 写过css的都知道,css是用来改变页面样式的.但它不是一种编程语言,没有变量,函数,继承等功能,只能一条条抒写样式语句很死板.在这个工具决定效率的时代,这是不能容忍的事情.怎样 ...

  5. centos 编译安装nginx

    这里选用的是nginx-1.10.1稳定版,其基础依赖库有gcc.gcc-c++.pcre.zlib和openssl. pcre.zlib和openssl这三个依赖库在安装nginx时无需编译安装,下 ...

  6. Jstatd方式远程监控Linux下 JVM运行情况

    前言 最近一个项目部署在服务器上运行时出现了问题,经过排查发现是java内存溢出的问题,所以为了实时监控服务器java内存的情况,需要远程查看服务器上JVM内存的一些情况.另外服务器系统是CentOS ...

  7. js中width,height,left,top计算

    ①offset    包括了元素的边框和内边距和滚动条 offsetWidth.offsetHeight元素的宽度和高度 offsetLeft .offsetTop元素相对于文档左边和顶部的距离(定位 ...

  8. .net: 不能忽视的break——寻找VS2010和VS2012编译器的一个小区别

    文中的问题来自于实际开发,但是实际开发中的代码逻辑比较复杂,因此下面的代码去掉了所有逻辑,只保留能体现问题的代码,类和都只为了说明问题,并不具有实际意义.下面首先看看下面的代码和现象. 1. 问题再现 ...

  9. on事件绑定阻止冒泡的问题

    当使用on进行事件绑定时当要给document绑定click,而子元素要禁止冒泡,那么子元素里面的子元素的click事件就会无效了, 下面无效版: $('#queue').on('click', '. ...

  10. Unity3DGUI:常用控件