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 題目連結 題目 略,請直接看原題. 前言 原本想說會不會也是要列式子解或者二分搜,沒 ...
随机推荐
- java中的ArrayList 、List、LinkedList、Collection关系详解
一.基础介绍(Set.List.Map) Set(集):集合中的元素不按特定方式排序,并且没有重复对象.他的有些实现类能对集合中的对象按特定方式排序. List(列表):集合中的元素按索引位置排序,可 ...
- Activity和Fragment之间解耦
看鸿洋博客:http://blog.csdn.net/lmj623565791/article/details/42628537,整理下一些关键点 public class ContentFragme ...
- 个人PE流程备忘
insmod memdisk linux16 /boot/memdisk iso raw initrd16 /iso/Win8PE.iso
- find中的-print0和xargs中-0的区别
默认情况下, find 每输出一个文件名, 后面都会接着输出一个换行符 ('\n'), 因此我们看到的 find 的输出都是一行一行的: [bash-4.1.5] ; ls -l total 0 -r ...
- python连接mysql、oracle小例子
import MySQLdbimport cx_Oracle as oraimport pandas as pdfrom sqlalchemy import create_eng ...
- myeclipse启动服务器时,tomcat出错问题
启动服务器,错误提示: Launching web on myeclipse tomcat has encountered a problem An internal error occurred d ...
- kali客户端攻击
浏览器攻击 browser_autpwn2 (BAP2) mkdir /test 为接受响应的服务器创建目录 use auxiliary/server/browser_autopwn2 set ...
- db2 表空间容器调整
1.查看当前容器的分布,并确定如何调整 db2look -d sample -l -cor -dp -o dd.sql 2.给表空间添加容器 db2 "alter tablespace tb ...
- 大数据揭示的10个常见JAVA编程错误
初学者最常犯的编程错误是什么呢?有可能他们总是混淆等值(==)与赋值(=),或者 & 和 &&:也有可能是他们在循环中使用错误的分隔符(for (int i = 0, i &l ...
- mob.com Android studio 配置环境