题目链接:http://codeforces.com/problemset/problem/702/D

题意:

  一个人要去邮局取东西,从家到达邮局的距离为 d, 它可以选择步行或者开车,车每走 k 公里就要花费 t秒修一次才可以继续开,车每公里花费 a秒,步行每公里花费 b秒。依次给出d, k, a, b, t。问最少需要花费多少时间到达邮局。车刚开始时是好的。

思路:

  首先可以模拟一下,可以想到,如果车速比步速块,那么前 k公里路肯定选择坐车,因为开始时车是好的,不用花费多余的时间来修理车,否则直接全程步行就好了(步速大于车速,必选步行)。接下来我们把剩余的 d - k (d > k) 公里路分为两段,设 othr = d % k, car = d / k,则就分为 car * k 和 othr两段路。对于前car * k 公里路,如果选择开车(此时车已经坏了),那么总时间就等于开车所需要的时间加上修车所需要的时间, t1 = car * k * a + car * t, 如果选择步行,那么t2 = car * k * b;选择时间短的就好了。对于剩余的 othr 公里路开车需要 t + othr * a, 步行需要 othr * b,同样选择比较小的就好了。

注意:

  有可能d < k,那么此时直接比较车速和步速,哪个快选择哪个就好了。

代码:

 #include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <string>
#define mearv(a, b) memset(a, b, sizeof(a))
#define mestrc(a, b, c) memset(&(a), b, sizeof(c)) typedef long long LL;
using namespace std;
const int MAXN = ;
const LL INF = 1e15; int main() {
LL d, k, a, b, t;
scanf("%I64d%I64d%I64d%I64d%I64d", &d, &k, &a, &b, &t);
LL ans = ;
if(a < b) {
if(d > k) ans += k * a, d -= k;//此时可以把路程分为两段。
else ans += d * a, d = ;//总路程小于乘一次车的路程,则直接开车走完全程
}
else ans += d * b, d = ;//b步速大于车速,步行走完全程
if(d > ) {
LL othr = d % k, car = d / k;
if(car * (t + k * a) < car * k * b) ans += car * (t + k * a); //前car * k 公里的选择
else ans += car * k * b;
if(othr * b < t + othr * a) ans += othr * b; //后 othr公里的选择
else ans += t + othr * a;
}
printf("%I64d\n", ans);
return ;
}

Codeforces 702D Road to Post Office(模拟 + 公式推导)的更多相关文章

  1. CodeForces 702D Road to Post Office

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

  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_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. Educational Codeforces Round 15 Road to Post Office

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

  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. P2124 奶牛美容

    题目描述 输入输出格式 输入格式: 输出格式: 输入输出样例 输入样例#1: 6 16 ................ ..XXXX....XXX... ...XXXX....XX... .XXXX ...

  2. hdu 6200 mustedge mustedge(并查集+树状数组 或者 LCT 缩点)

    hdu 6200 mustedge mustedge(并查集+树状数组 或者 LCT 缩点) 题意: 给一张无向连通图,有两种操作 1 u v 加一条边(u,v) 2 u v 计算u到v路径上桥的个数 ...

  3. BZOJ3671 [Noi2014]随机数生成器 【贪心】

    题目链接 BZOJ3671 题解 模拟题意生成矩阵贪心从小选择即可 每选择一个,就标记其左下右上矩阵 由于每次都是标记一个到边界的矩阵,所以一旦遇到标记过就直接退出即可,可以保证复杂度 还有就是空间和 ...

  4. watch用法小记

    By francis_hao    Jun 30,2017   watch:周期性的执行一个一个程序,并全屏显示输出 概述 watch [options] command   描述 watch重复的运 ...

  5. POJ1182:食物链(并查集)

    食物链 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 94930   Accepted: 28666 Description ...

  6. codeforces 1060 A

    https://codeforces.com/contest/1060/problem/A 题意:电话号码是以8开头的11位数,给你n 个数问最多可以有多少个电话号码 题解:min(8的个数,n/11 ...

  7. Springmvc 流程图

  8. sql数据库的链接方式

    今天看见了一个数据库的链接方法,给转载了,记得我刚刚学DAO的时候老是要记载这些东西,所以就上博客园上面看了看,就转过来了... MySQL: String Driver="com.mysq ...

  9. swift关于is和as的解释

    http://tieba.baidu.com/p/3155277323 在Swift中,类型检查使用is和as操作符来实现. is操作符用来检查一个实例是否是某种特定类型,如果是返回true,否则返回 ...

  10. tmux下vim颜色不正常问题

    在解决了tmux下,make menuconfig颜色不正常问题https://www.cnblogs.com/zqb-all/p/9702582.html后,引入了新的问题,vim颜色错乱. 尝试了 ...