[优先队列+贪心]poj3614 Sunscreen
来源:互联网 发布:redis mysql同步 编辑:程序博客网 时间:2024/06/06 12:53
http://poj.org/problem?id=3614
那么将奶牛按照阳光强度的最小值从小到大排序。
将防晒霜也按照能固定的阳光强度从小到大排序
从最小的防晒霜枚举,将所有符合 最小值小于等于该防晒霜的 奶牛的 最大值 放入优先队列之中。
然后优先队列是小值先出
所以就可以将这些最大值中的最小的取出来。更新答案。
#include <iostream>#include<algorithm>#include<queue>#include<math.h>#include<stdio.h>#include<string.h>const int INF=0x3f3f3f3f;using namespace std;const int MAXN = 10000;int C,L;typedef pair<int,int> P;priority_queue<int,vector<int>,greater<int> > q;P cow[MAXN],bot[MAXN];bool cmp(P a,P b){ return a.first < b.first;}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,cmp); sort(bot,bot+L,cmp); 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 a = q.top(); q.pop(); if (a<bot[i].first) continue; ans++; bot[i].second--; } } printf("%d\n",ans); return 0;}
0 0
- poj3614 Sunscreen 贪心 优先队列
- [POJ3614]Sunscreen[贪心][优先队列]
- [优先队列+贪心]poj3614 Sunscreen
- poj3614 Sunscreen (优先队列+贪心)
- poj3614 Sunscreen 【优先队列】
- POJ3614-Sunscreen-优先队列
- poj3614 Sunscreen贪心+优先队列(怕晒的奶牛)
- poj3614 Sunscreen 贪心+单调队列
- poj3614-贪心、优先队列
- POJ3614 Sunscreen 【贪心】
- poj3164 Sunscreen(优先队列+贪心)
- Sunscreen (贪心+优先队列)
- POJ 3614 Sunscreen 优先队列 贪心
- POJ 3614 Sunscreen 贪心 优先队列
- POJ 3614 Sunscreen (贪心、优先队列)
- Sunscreen (poj 3614 贪心+优先队列)
- POJ 3614:Sunscreen 贪心+优先队列
- poj 3614 Sunscreen 贪心 优先队列
- Python 的列表排序
- iO开发资料
- WPF中WebBrowser的使用方法及分析
- POJ-1979 Red and Black
- android unit test
- [优先队列+贪心]poj3614 Sunscreen
- C# 获取当前路径方法
- 结构体的定义及其初始化方法And typedef的使用-----------权当笔记了
- [kuangbin带你飞]专题四 最短路练习
- 数据结构基础(22)--红黑树的设计与实现(上)
- Mybatis学习笔记-事务管理详解
- Android中inflate简介
- BFS
- 工作周记