Codeforces 702D Road to Post Office(模拟 + 公式推导)
题目链接: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(模拟 + 公式推导)的更多相关文章
- CodeForces 702D Road to Post Office
答案的来源不外乎于3种情况: 纯粹走路,用时记为${t_1}$:纯粹乘车,用时记为${t_2}$:乘车一定距离,然后走路,用时记为${t_3}$. 但是${t_1}$显然不可能成为最优解. 前两个时间 ...
- codeforce 702D Road to Post Office 物理计算路程题
http://codeforces.com/contest/702 题意:人到邮局去,距离d,汽车在出故障前能跑k,汽车1公里耗时a,人每公里耗时b,修理汽车时间t,问到达终点最短时间 思路:计算车和 ...
- 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 ...
- 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 ...
- 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 ...
- Educational Codeforces Round 15 Road to Post Office
Road to Post Office 题意: 一个人要从0走到d,可以坐车走k米,之后车就会坏,你可以修或不修,修要花t时间,坐车单位距离花费a时间,走路单位距离花费b时间,问到d的最短时间. 题解 ...
- 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 ...
- cf702D Road to Post Office
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...
- D. Road to Post Office 解析(思維)
Codeforce 702 D. Road to Post Office 解析(思維) 今天我們來看看CF702D 題目連結 題目 略,請直接看原題. 前言 原本想說會不會也是要列式子解或者二分搜,沒 ...
随机推荐
- 遇到问题---java---git下载的maven项目web用tomcat发布时不带子项目
遇到的情况是用git下载maven项目,然后用mvn eclipse:eclipse命令标记为eclipse项目之后,使用maven插件导入之后用tomcat发布运行,发现maven关联的几个子项目没 ...
- nginx对指定目录做代理
环境介绍 web1,作为前端端服务器,访问地址是http://192.168.1.1,要将http://192.168.1.1/bbs的请求交给web2.在web1的网站根目录下并没有bbs目录 we ...
- Sync Data to AWS S3 on Windows Box
1. Install AWS CLI first, windows download link https://s3.amazonaws.com/aws-cli/AWSCLI64.msi 2. The ...
- js操作div的显隐
<!DOCTYPE html><html> <head> <title> new document </title> <meta ht ...
- oracle 数据库图形化工具 sqldeveloper
1. 安装完成Oracle数据库,点击左下角[开始]菜单,在所有程序中打开[Oracle] 2. 在开始菜单,展开Oracle数据库,安装文件,然后打开[应用程序开发].可以看到[sqldevelop ...
- shelve,xml,re模块
一.shelve模块 shelve模块比pickle模块简单,只有一个open函数,返回类似字典的对象,可读可写;key必须为字符串,而值可以是python所支持的数据类型 import shelve ...
- django执行sql
http://docs.30c.org/djangobook2/chapter10/ def first_names(self, last_name): cursor = connection.cur ...
- [Leetcode Week2]Merge Intervals
Merge Intervals题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/merge-intervals/description/ Descript ...
- 【洛谷P3709】大爷的字符串题
看这题网上居然还没人写blog,怕是都去看洛谷自带的了-- 你才是字符串!你全家都是字符串!这题跟字符串没多大关系,只是出题人lxl想要吐槽某中学而已--... 其实这题说白了就是问区间里出现最多的数 ...
- JS计算两个时间差的问题
计算两个时间差的问题 function getDateIsMatching(){ var pactbegindate=$("#loanbegindate").datetimebox ...