BZOJ1747 [Usaco2005 open]Expedition 探险

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

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

 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 }

时间: 2024-11-07 07:12:14

BZOJ1747 [Usaco2005 open]Expedition 探险的相关文章

托福分类词汇

托福分类词汇表(共17类863个常用单词) 一.   psychology 心理 1.       mental 心理的 2.       physical 身体的,物质的,物理的 3.       spiritual 心灵的 4.       conformity 从众 5.       majority 多数人 6.       minority 少数人 7.       threshold judgment (心理学)初始性判断 8.       subject 受实验对象 9.     

POJ 2431 Expedition(探险)

Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rather poor drivers, the cows unfortunately managed to run over a rock and puncture the truck's f

bzoj1730 [Usaco2005 dec]Barn Expansion 牛棚扩张

1730: [Usaco2005 dec]Barn Expansion 牛棚扩张 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 134  Solved: 72[Submit][Status][Discuss] Description Farmer John has N (1 <= N <= 25,000) rectangular barns on his farm, all with sides parallel to the X and Y ax

bzoj1754[Usaco2005 qua]Bull Math*

bzoj1754[Usaco2005 qua]Bull Math 题意: 求两个正整数的积,每个数≤40位. 题解: 为什么C++不能支持高精度呢…… 代码: 1 a=int(raw_input()) 2 b=int(raw_input()) 3 print a*b 20160831

bzoj1689[Usaco2005 Open] Muddy roads 泥泞的路

bzoj1689[Usaco2005 Open] Muddy roads 泥泞的路 题意: 数轴上n个互不覆盖的区间,问要用多少个长为L的线段覆盖.n≤10000 题解: 排序区间,然后从每个区间左端点开始铺木板,如果最后一块木板能够铺到下一个区间就铺,以此类推. 代码: 1 #include <cstdio> 2 #include <algorithm> 3 #include <cstring> 4 #define maxn 10100 5 #define inc(i

【POJ2431】Expedition

Expedition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8434   Accepted: 2474 Description A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rather poor drivers, the cows unfortunately managed to

1740: [Usaco2005 mar]Yogurt factory 奶酪工厂

1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 119  Solved: 100[Submit][Status][Discuss] Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the next N (1 <= N <= 10

1751: [Usaco2005 qua]Lake Counting

1751: [Usaco2005 qua]Lake Counting Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 190  Solved: 150[Submit][Status][Discuss] Description Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle

BZOJ 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚

题目 1672: [Usaco2005 Dec]Cleaning Shifts 清理牛棚 Time Limit: 5 Sec  Memory Limit: 64 MB Description Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now require their barn to be immaculate. Farmer John, the most