POJ3614-Sunscreen
来源:互联网 发布:做假图软件 编辑:程序博客网 时间:2024/06/16 21:49
每一种防晒霜可以给多个牛使用,这时候该如何决策呢?
维护一个优先队列,按maxSPF从小到大的顺序排列。这是为了尽量把SPF小的防晒霜给maxSPF小的牛。
首先将牛和防晒霜进行排序,然后按防晒霜的SPF从小到大分配给可用的牛。
#include <cstdio>#include <algorithm>#include <functional>#include <queue>using namespace std;typedef pair<int, int> P;const int MAXN = 2500;P cows[MAXN+5];P lot[MAXN+5];priority_queue<int, vector<int>, greater<int> > que;int main(){ int c, l; scanf("%d%d", &c, &l); for (int i = 0; i < c; i++) scanf("%d%d", &cows[i].first, &cows[i].second); sort(cows, cows + c); for (int i = 0; i < l; i++) scanf("%d%d", &lot[i].first, &lot[i].second); sort(lot, lot + l); int res = 0; int j = 0; for (int i = 0; i < l; i++) { while (j < c && cows[j].first <= lot[i].first) { que.push(cows[j].second); j++; } while (!que.empty() && lot[i].second) { int cow = que.top(); que.pop(); if (cow >= lot[i].first) { lot[i].second--; res++; } } } printf("%d\n", res); return 0;}
0 0
- POJ3614--Sunscreen
- POJ3614-Sunscreen
- poj3614 Sunscreen 【优先队列】
- POJ3614 Sunscreen 【贪心】
- POJ3614-Sunscreen-优先队列
- poj3614 Sunscreen 贪心+单调队列
- poj3614 Sunscreen 贪心 优先队列
- [POJ3614]Sunscreen[贪心][优先队列]
- [优先队列+贪心]poj3614 Sunscreen
- poj3614 Sunscreen (优先队列+贪心)
- 【POJ3614】【USACO 2007 Nov Gold】 3.Sunscreen 贪心
- poj3614 Sunscreen贪心+优先队列(怕晒的奶牛)
- poj3614
- poj3614
- poj3614
- poj3614
- poj3614
- poj3614
- Android 单元测试
- VR硬件技术三大标准深度解析
- h5第三章
- 几种常见排序算法
- java并发之原子性、可见性、有序性
- POJ3614-Sunscreen
- left join、rightjoin的使用
- 实用的Myeclipse10 优化设置
- Volley,小并发网络请求的好帮手
- Codeforces 554C Kyoya and Colored Balls 【dp + 组合数学】
- 框架之浅入浅出
- receiver type "className" for instance message is a forward declaration
- strcpy、memcpy和memmove的区别和实现
- HDOJ 3415 Max Sum of Max-K-sub-sequence