贪心。当前位置满油可达的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的更多相关文章

  1. 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 ...

  2. 8VC Venture Cup 2016 - Final Round (Div. 1 Edition) E - Preorder Test 树形dp

    E - Preorder Test 思路:想到二分答案了之后就不难啦, 对于每个答案用树形dp取check, 如果二分的值是val, dp[ i ]表示 i 这棵子树答案不低于val的可以访问的 最多 ...

  3. 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 ...

  4. 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 ...

  5. 8VC Venture Cup 2016 - Final Round C. Package Delivery 优先队列

    C. Package Delivery 题目连接: http://www.codeforces.com/contest/627/problem/C Description Johnny drives ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 洛谷P2863 [USACO06JAN]牛的舞会The Cow Prom

    代码是粘的,庆幸我还能看懂. #include<iostream> #include<cstdio> #include<cmath> #include<alg ...

  2. iTOP-4418开发板最新资料及例程

    开发板资料: 开发板硬件资源: 1.POWER电源接口 电源输入为 5V/2A+,给核心板 AXP228 电源管理芯片提供 5V 电源. 2.SWITCH电源开关 轻触电源开关可以控制开发板电源通断. ...

  3. 【C语言】控制台窗口图形界面编程(八):键盘事件

    目录 00. 目录 01. INPUT_RECORD结构 02. KEY_EVENT_RECORD结构 03. ReadConsoleInput函数 04. 示例程序 00. 目录 01. INPUT ...

  4. python selenium定位总结(转)

    转自:http://www.cnblogs.com/yufeihlf/p/5717291.html 父子定位元素 查找有父亲元素的标签名为span,它的所有标签名叫input的子元素 find_ele ...

  5. [Python3网络爬虫开发实战] 1.2.4-GeckoDriver的安装

    上一节中,我们了解了ChromeDriver的配置方法,配置完成之后便可以用Selenium驱动Chrome浏览器来做相应网页的抓取. 那么对于Firefox来说,也可以使用同样的方式完成Seleni ...

  6. 【memcached】memcached中flags字段的作用

    我们一般只注意到memcached的数据结构是key,value,今天看memcached源代码的时候,盯上了flags,没看明白.后来问了一下同事,说PHP当中使用flags标记,标识memcach ...

  7. PHP:验证邮箱合法性

    文章来源:http://www.cnblogs.com/hello-tl/p/7592304.html /** * [verifyPhone description] 效验邮箱号合法性 * @para ...

  8. 1. 垃圾收集简介 - GC参考手册

    说明: 在本文中, Garbage Collection 翻译为 “垃圾收集”, garbage collector 翻译为 “垃圾收集器”; 一般认为, 垃圾回收 和 垃圾收集 是同义词. Mino ...

  9. python爬虫(三)

    Requests模块 这个库的标准文档有个极其幽默的地方就是它的中文翻译,我就截取个开头部分,如下图: 是不是很搞笑,在正文中还有许多,管中窥豹,可见一斑.通过我的使用,感觉Requests库的确是给 ...

  10. Oracle 实现查询不区分大小写(SQL实现)

    转为小写  LOWER('ABC') 结果 abc转为大写  UPPER('aBc') 结果 ABC 将数据库字段数据和前台接受的值全部转换为大写或者小写 例: select * from table ...