首先我们可以发现如果错过了一个加油站,而继续往前走的时候没有油了,可以再假装之前经过加油站的时候加过油

于是我们维护一个大根堆,表示错过的加油站是哪些,每当没有油的时候从堆顶取出最大值加上去即可

 1 /**************************************************************
 2     Problem: 1747
 3     User: rausen
 4     Language: C++
 5     Result: Accepted
 6     Time:20 ms
 7     Memory:916 kb
 8 ****************************************************************/
 9
10 #include <cstdio>
11 #include <algorithm>
12 #include <queue>
13
14 using namespace std;
15 const int N = 1e4 + 5;
16
17 inline int read();
18
19 struct data {
20     int w, add;
21
22     inline void get() {
23         w = read(), add = read();
24     }
25
26     inline bool operator < (const data &d) const {
27         return w > d.w;
28     }
29 } a[N];
30
31 int n, tot, ans;
32 priority_queue <int> h;
33
34 int main() {
35     int i;
36     n = read();
37     for (i = 1; i <= n; ++i) a[i].get();
38     a[0].w = read(), tot = read();
39     sort(a + 1, a + n + 1);
40     a[n + 1].w = 0;
41     for (i = 1; i <= n + 1; ++i) {
42         tot -= (a[i - 1].w - a[i].w);
43         while (tot < 0 && !h.empty()) {
44             ++ans;
45             tot += h.top(), h.pop();
46         }
47         if (tot < 0) {
48             puts("-1");
49             return 0;
50         }
51         h.push(a[i].add);
52     }
53     printf("%d\n", ans);
54     return 0;
55 }
56
57 inline int read() {
58     static int x;
59     static char ch;
60     x = 0, ch = getchar();
61     while (ch < '0' || '9' < ch)
62         ch = getchar();
63     while ('0' <= ch && ch <= '9') {
64         x = x * 10 + ch - '0';
65         ch = getchar();
66     }
67     return x;
68 }

View Code

转载于:https://www.cnblogs.com/rausen/p/4480575.html

BZOJ1747 [Usaco2005 open]Expedition 探险相关推荐

  1. expedition(探险)(python)

    题目 A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rather ...

  2. [托业]TOEIC词汇汇总(完整篇)4

    九.Business Correspondence & Advertisement 商业书信及广告(1) 1.advertisement                             ...

  3. 英语CET-6级(一)

    (本文内容为个人笔记分享) How To Get Over Post Holiday Depression [CET-6] 如何克服假期后的意志消沉 get over : 克服;从(不快或疾病中)恢复 ...

  4. 【POJ No. 2431】 丛林探险 Expedition

    [POJ No. 2431] 丛林探险 Expedition 北大OJ 题目地址 [题意] 一群人开着一辆卡车冒险进入丛林深处,卡车油箱坏了,每走1米就会漏1升油,他们需要到最近的城镇(距离不超过10 ...

  5. 【小白爬POJ2431】3.6 探险车加油问 Expedition

    [小白爬POJ2431]3.6 探险车加油问题 Expedition 题目 Description Input Output Sample Input Sample Output Hint 思路 PO ...

  6. 传微软长角牛正式命名:Windows e-XPedition

    根据外国网站透露,有来自微软内部的消息指微软下一代的Windows,也就是大家一直称呼其为"长角牛"(Longhorn)的新版操作系统的正式名称可能是Microsoft Windo ...

  7. F#探险之旅(三):命令式编程(上)

    F#系列随笔索引页面 在本系列的第二部分(函数式编程上.中.下)中,我们了解了如何使用F#进行纯粹的函数式编程.但是在一些情况下,比如I/O,几乎不能避免改变状态,也就是说会带来side effect ...

  8. bzoj1688[Usaco2005 Open]Disease Manangement 疾病管理*

    bzoj1688[Usaco2005 Open]Disease Manangement 疾病管理 题意: n头牛,d种疾病,每头牛都患一些疾病,现在要求选出最多的牛,使这些牛患病的种类数不超过k.n≤ ...

  9. 1677: [Usaco2005 Jan]Sumsets 求和

    1677: [Usaco2005 Jan]Sumsets 求和 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 626  Solved: 348 [Sub ...

最新文章

  1. 【.Net MF网络开发板研究-04】Socket编程之服务端
  2. js---25桥模式
  3. P7 频域分析法-《Matlab/Simulink与控制系统仿真》程序指令总结
  4. <meta name=“robots“ content=“index,follow“>的解释
  5. Linux性能监控-Top
  6. 数据结构之串:基本概念
  7. 将一个包含有2层数据分组的表输出到EXCEL表里,并分组统计
  8. hdu2642二维树状数组单点更新+区间查询
  9. 《Unix/Linux网络日志分析与流量监控》2014年11月底出版
  10. 【BERT实践】看不懂bert没关系,用起来so easy!
  11. yaahp使用教程_yaahp层次分析法软件
  12. 2.6一个小工具的使用snipaste
  13. 口袋超萌服务器维护中,口袋超萌手游加速攻略 口袋超萌加速方法说明
  14. atsc-m/h现状
  15. 镍基合金600材质,用什么配套焊材 by阿斯米合金
  16. vmware 提示该虚拟机正在使用中
  17. mes系统和plc通讯案例_MES系统与PLC数据集成主要方式
  18. 未来流行遛机器狗,也许能解决城市宠物背后的矛盾
  19. 抓包工具fiddler使用与理论的理解
  20. Learning ROS for Robotics Programming Second Edition学习笔记(七) indigo PCL xtion pro live

热门文章

  1. python 列表算平均分_python平均列表
  2. linux终端中运行网银盾,Linux下使用Virtualbox安装 Windows 7 操作网银攻略
  3. 中南大学c语言上机考试题库,中南大学C++题库之选择题
  4. 如何在空硬盘Linux系统,Linux系统如何新增一块硬盘
  5. android 封装的popwindow,Android UI开发 popupwindow介绍以及代码实例
  6. 崇阳计算机技校,湖北省崇阳县龙翔技工学校
  7. 华为机考HJ2计算字符个数
  8. Matplitlib绘图入门1,这一篇就够了
  9. ubuntu + oepncv + PCL + realsenseSDK + ROS + OpenVino开发环境搭建
  10. TensorFlow(7)卷积神经网络实战(1)(可视化)