8VC Venture Cup 2016 - Final Round (Div2) E
贪心。当前位置满油可达的gas station中,如果有比它小的,则加油至第一个比他小的。没有,则加满油,先到达这些station中最小的。注意数的范围即可。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL long long using namespace std; const int MAXN = 200050; int d, n, m; int gp[MAXN], gpz[MAXN];
int fl[MAXN]; struct gas{
int pos, price;
}g[MAXN]; bool cmp(gas a, gas b){
if(a.pos < b.pos) return true;
return false;
} int main(){
scanf("%d%d%d", &d, &n, &m); gp[0] = 0, gpz[0] = 1e7;
for(int i = 1; i <= m; i++){
scanf("%d%d", &g[i].pos, &g[i].price);
} sort(g + 1, g + 1 + m, cmp); for(int i = 1; i <= m; i++){
gp[i] = g[i].pos, gpz[i] = g[i].price;
} gp[m + 1] = d, gpz[m + 1] = 0; /*
for(int i = 0; i<= m + 1; i++)
cout <<gp[i] <<" "<< gpz[i] << endl;
cout << endl;
*/
int mindist = -1; for(int i = 0; i <= m; i++){
mindist = max(mindist, gp[i + 1] - gp[i]);
} // cout << mindist << endl; if(mindist > n){
puts("-1");
return 0;
} if(d <= n){
puts("0");
return 0;
} for(int i = m; i >= 0; i--){
if(gpz[i + 1] <= gpz[i]){
fl[i] = i + 1;
}
else {
int tmp = i + 1;
while(gpz[fl[tmp]] > gpz[i]){
tmp = fl[tmp];
}
fl[i] = fl[tmp];
}
}
/*
for(int i = 0; i<= m; i++){
cout << fl[i] <<" ";
}
cout << endl; */ LL ans = 0;
int liter = n; for(int l = 0; l < m+ 1; ){
if(gp[fl[l]] - gp[l] > n){
ans += (LL)(n - liter) * gpz[l];
int tmp = l + 1;
while(gp[fl[tmp]] - gp[l] <= n){
tmp = fl[tmp];
}
liter = n - (gp[tmp] - gp[l]);
l = tmp;
}
else{
int tmp = fl[l];
if(tmp == m + 1){
ans += (LL)(d - gp[l] - liter) * gpz[l];
break;
}
else{
if(gp[tmp] - gp[l] <= liter){
liter -= gp[tmp] - gp[l];
}
else{
ans += (LL)(gp[tmp] - gp[l] - liter)*gpz[l];
liter = 0;
}
l = tmp;
}
}
// cout << l << endl;
// system("pause");
}
cout << ans << endl; }
8VC Venture Cup 2016 - Final Round (Div2) E的更多相关文章
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition)
暴力 A - Orchestra import java.io.*; import java.util.*; public class Main { public static void main(S ...
- 8VC Venture Cup 2016 - Final Round (Div. 1 Edition) E - Preorder Test 树形dp
E - Preorder Test 思路:想到二分答案了之后就不难啦, 对于每个答案用树形dp取check, 如果二分的值是val, dp[ i ]表示 i 这棵子树答案不低于val的可以访问的 最多 ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) A
A. Orchestra time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 8VC Venture Cup 2016 - Final Round D. Preorder Test 二分 树形dp
Preorder Test 题目连接: http://www.codeforces.com/contest/627/problem/D Description For his computer sci ...
- 8VC Venture Cup 2016 - Final Round C. Package Delivery 优先队列
C. Package Delivery 题目连接: http://www.codeforces.com/contest/627/problem/C Description Johnny drives ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) D. Factory Repairs 树状数组
D. Factory Repairs 题目连接: http://www.codeforces.com/contest/635/problem/D Description A factory produ ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) C. XOR Equation 数学
C. XOR Equation 题目连接: http://www.codeforces.com/contest/635/problem/C Description Two positive integ ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition)B. sland Puzzle 水题
B. sland Puzzle 题目连接: http://www.codeforces.com/contest/635/problem/B Description A remote island ch ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) A. Orchestra 水题
A. Orchestra 题目连接: http://www.codeforces.com/contest/635/problem/A Description Paul is at the orches ...
随机推荐
- jq一些常用的交互效果
jq回到顶部: //回到顶部 $(window).scroll(function() { //执行处理的代码 var a = document.body.scrollTop; if($(documen ...
- js几个逻辑运算符的形象概括
“&&”是逻辑与操作符,只有“&&”两边值同时满足(同时为真),整个表达式值才为真. b>a && b<c //“&& ...
- struts2 针对类型转换出错的处理
在类型转换出错时,需要在页面上显示友好提示: 类型转换出错时,会抛出一个运行时异常,程序会根据建立的属性文件,显示相应的错误提示. 实现方法: 1)新建局部属性文件或者全局属性文件 局部属性文件:放置 ...
- WebStorm改变字体大小以及更换背景颜色
参考文章:https://blog.csdn.net/weixin_42676530/article/details/82961279
- 第2节 mapreduce深入学习:2、3
第2节 mapreduce深入学习:2.MapReduce的分区:3.分区案例的补充完成运行实现 在MapReduce中,通过我们指定分区,会将同一个分区的数据发送到同一个reduce当中进行处理,例 ...
- 跳转QQ聊天窗口
1. 点击按钮跳转QQ聊天窗口,若不是好友,先加好友 <a href=" tencent://message/?uin=QQ号" target="_blank&qu ...
- Libjingle 库
Libjingle 是google talk voice(语音聊天) 和 p2p interoperability(点对点操作)库,是提供了google talk,p2p文件共享和语音呼叫能力的组件集 ...
- forEach的使用方法
[-] 1 js 数组循环遍历 2 forEach 函数 3 让IE兼容forEach方法 4 如何跳出循环 1. js 数组循环遍历. 数组循环变量,最先想到的就是 for(var i= ...
- 零基础入门学习Python(8)--了不起的分支和循环2
前言 上节课小甲鱼教大家如何正确的打飞机,其要点是判断和循环,判断就是该不该做某事,循环就是持续做某事 知识点 写一个程序 按照100分制,90分以上成绩为A,80到90为B,60到80为C,60以下 ...
- Python接口测试中通过登录接口获取实时token
1.封装login_token 2.headers:对应登录请求头部信息 3.request_param:登录的参数数据 4.json.dumps:将一个Python数据结构转换为JSON 5.dic ...