poj 3614
来源:互联网 发布:json格式 编辑:程序博客网 时间:2024/05/21 11:18
那么将奶牛按照阳光强度的最小值从小到大排序。
将防晒霜也按照能固定的阳光强度从小到大排序
从最小的防晒霜枚举,将所有符合 minSPF 小于等于该防晒霜的SPF 的奶牛 放入优先队列之中。
然后优先队列是小值先出
所以就可以将优先队列最大值 大于等于 防晒霜的SPF的取出来。
AC代码:
#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>#include <map>#include <vector>#include <queue>#define MAXN 2555#define INF 1000000007using namespace std;int C, L;typedef pair<int, int> P;priority_queue<int, vector<int>, greater<int> > q;P cow[MAXN], bot[MAXN];int main(){ scanf("%d%d", &C, &L); for(int i = 0; i < C; i++) scanf("%d%d", &cow[i].first, &cow[i].second); for(int i = 0; i < L; i++) scanf("%d%d", &bot[i].first, &bot[i].second); sort(cow, cow + C); sort(bot, bot + L); int j = 0, ans = 0; for(int i = 0; i < L; i++) { while(j < C && cow[j].first <= bot[i].first) { q.push(cow[j].second); j++; } while(!q.empty() && bot[i].second) { int x = q.top(); q.pop(); if(x < bot[i].first) continue; ans++; bot[i].second--; } } printf("%d\n", ans); return 0;}
#include <iostream>#include <queue>#include <vector>#include <map>#include <algorithm>using namespace std;const int MAX = 2505;typedef pair<int, int> P;priority_queue<int, vector<int>, greater<int> > que;int c, l;P cow[MAX], bot[MAX];int main() {scanf("%d%d", &c, &l);for(int i=0; i<c; i++)scanf("%d%d", &cow[i].first, &cow[i].second);for(int i=0; i<l; i++)scanf("%d%d", &bot[i].first, &bot[i].second);sort(cow, cow+c);sort(bot, bot+l);int j=0, ans = 0;for(int i=0; i<l; i++) {while(j < c && cow[i].first <= bot[i].first) {que.push(cow[j].second);j++;}while(!que.empty() && bot[i].second) {int x = que.top();que.pop();if(x < bot[i].first)continue;ans++;bot[i].second--;}}printf("%d\n", ans);return 0;}
0 0
- poj 3614
- poj 3614
- poj-3614
- poj 3614
- poj 3614
- poj 3614
- POJ 3614
- 【POJ】3614
- poj 3614 Sunscreen
- poj 3614 Sunscreen 贪心
- poj 3614 Sunscreen (贪心)
- POJ-3614-Sunscreen
- POJ 3614 Sunscreen
- poj-3614-Sunscreen
- POJ 3614 Sunscree
- poj 3614 Sunscreen 贪心
- POJ-3614 sunscreen
- poj 3614 贪心
- MySQL server has gone away 或 lost connection to MySQL server during query
- Spark算子:RDD基本转换操作(3)–randomSplit、glom
- js根据日期获取本周的开始日期和结束日期
- 驾照考完之后
- Spark算子:RDD基本转换操作(2)–coalesce、repartition
- poj 3614
- Spark算子:RDD创建操作
- 随机梯度下降(Stochastic gradient descent)和 批量梯度下降(Batch gradient descent )
- CUDA学习笔记之 CUDA存储器模型
- MongoDB数据迁移方案
- 上传AppStore时,适配iOS10
- An internal error occurred during: "J2EE Component Mapping Update".
- 【原创】【OpenJudge】8782:乘积最大
- binutils编译