答案的来源不外乎于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. JQuery动态操作表格

    新人,小白一枚,刚刚参加工作,所以会在这里记录一些遇到的问题. 最近要做的东西,是对一个表格动态的添加行,删除行,并且对表格中内容进行非空验证. <!DOCTYPE html> <h ...

  2. python下实现汉诺塔

    汉诺塔是印度一个古老传说的益智玩具.汉诺塔的移动也可以看做是递归函数. 我们对柱子编号为a, b, c,将所有圆盘从a移到c可以描述为: 如果a只有一个圆盘,可以直接移动到c: 如果a有N个圆盘,可以 ...

  3. 【1】Hover 效果收集

    各种 hover 效果  github repository>>  git 仓库 1. 背景图的 hover 效果 原页面>> githubSite>>

  4. linux查找文件的命令【转】

    原文链接:http://www.ruanyifeng.com/blog/2009/10/5_ways_to_search_for_files_using_the_terminal.html 1. fi ...

  5. python爬虫框架scrapy初识(一)

    Scrapy介绍 Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中.所谓网络爬虫,就是一个在网上到处或定向抓取数据的 ...

  6. leetcode 024

    Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2-&g ...

  7. 8个不可不知的Mac OS X专用命令行工具【转】

    OS X的终端下通用很多Unix的工具和脚本.如果从Linux迁移到OS X会发现很多熟悉的命令和脚本工具,其实并没有任何区别. 但是OS X也提供了很多其他系统所没有的特别的命令行工具.我们推荐8个 ...

  8. unity3d使用litjson中文显示的问题

    我们在使用litjson时它的编码方式是unicode的,所以我将json转成string输出时显示的是unicode的编码.这样我们显示或者保存中文时不是很方便.我们可以将中文的unicode转成能 ...

  9. Unity3D脚本使用:游戏对象访问

    Unity3D中用到的组件 组件在js中对应的对象 使用如图: 注意:一个物体可以添加多个组件和多个js 同个物体上添加的js间引用

  10. USACO 3.2 Magic Squares

    Magic SquaresIOI'96 Following the success of the magic cube, Mr. Rubik invented its planar version, ...