CodeForces 702D Road to Post Office
答案的来源不外乎于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的更多相关文章
- Codeforces 702D Road to Post Office(模拟 + 公式推导)
题目链接:http://codeforces.com/problemset/problem/702/D 题意: 一个人要去邮局取东西,从家到达邮局的距离为 d, 它可以选择步行或者开车,车每走 k 公 ...
- 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 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 ...
- 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 題目連結 題目 略,請直接看原題. 前言 原本想說會不會也是要列式子解或者二分搜,沒 ...
随机推荐
- python-微博模拟登陆
微博的的模拟登陆是比较坑的,看了网上很多大神的帖子,自己又看了微博的登陆时的json数据:1.发现登陆时在输入账号时用chrome可以看到会有一个prelogin之类的网址,网址后面会有大串的随机数. ...
- keychain的使用
通常情况下,我们用NSUserDefaults存储数据信息,但是对于一些私密信息,比如密码.证书等等,就需要使用更为安全的keychain了.keychain里保存的信息不会因App被删除而丢失,在用 ...
- eclipse中svn提交过滤不需要的文件
eclipse>Preference>Team>Ignored Resource 添加 .settings .classpath .project
- ssh中的 Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
这个错误我整理了 半天才发现问题的存在. 尝试了网上的很多办法,但是最后都没有达到效果. 包括这两种: 第一种: web.xml种的配置 <filter> <filter-name ...
- Oracle与Sqlserver:Order by NULL值介绍
针对页面传参到in的子集中去进行查询操作的话,就会有in(xxx,null),这样就会导致查询的结果中其实直接过滤掉了null,根本就查不出来null的值.之前对于null的操作都是进行不同数据库的n ...
- java四种xml解析区别
1.DOM解析 dom解析是根据树形结构解析,将整个文档加载到内存中,因此对内存的要求较高,所以可以对该文档数据进行多次操作(增,删,改,查). 2.SAX解析 SAX解析是根据事件模型解析,边读取文 ...
- find中的-print0和xargs中-0的区别
默认情况下, find 每输出一个文件名, 后面都会接着输出一个换行符 ('\n'), 因此我们看到的 find 的输出都是一行一行的: [bash-4.1.5] ; ls -l total 0 -r ...
- 创建 userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings 的配置节处理程序时出错: 未能加载文件或程序集“System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”或它的某一个依赖项。系统没找到指定的文件
创建 userSettings/Microsoft.SqlServer.Configuration.LandingPage.Properties.Settings 的配置节处理程序时出错: 未能加载文 ...
- 笔记本光驱位安装固态硬盘及window系统一些过程记录
自己的笔记本电脑是13年买的 联想G480 i3 32位 2g内存,配置有点低,呵呵.当初刚毕业问家里要钱买的,到现在后悔没有买好一点的笔记本. 用着用着感觉内存不够用,网上就买了根内存条,买之前 ...
- 字串变换 (2002 年NOIP全国联赛提高组)
一道看似非常水的题 大意 :将一个字串 经过几种变换规则变为给定的另一个子串 ,求最小操作数. code[vs] 传送门 洛谷传送门 已知有两个字串 A, B 及一组字串变换的规则(至多6个规则): ...