poj3614 priority queue
来源:互联网 发布:阿里云空间登陆 编辑:程序博客网 时间:2024/06/07 00:21
Description
To avoid unsightly burns while tanning, each of the C (1 ≤ C ≤ 2500) cows must cover her hide with sunscreen when they're at the beach. Cow i has a minimum and maximum SPF rating (1 ≤ minSPFi ≤ 1,000; minSPFi ≤ maxSPFi ≤ 1,000) that will work. If the SPF rating is too low, the cow suffers sunburn; if the SPF rating is too high, the cow doesn't tan at all........
The cows have a picnic basket with L (1 ≤ L ≤ 2500) bottles of sunscreen lotion, each bottle i with an SPF rating SPFi (1 ≤ SPFi ≤ 1,000). Lotion bottle i can cover coveri cows with lotion. A cow may lotion from only one bottle.
What is the maximum number of cows that can protect themselves while tanning given the available lotions?
Input
* Line 1: Two space-separated integers: C and L
* Lines 2..C+1: Line i describes cow i's lotion requires with two integers: minSPFi and maxSPFi
* Lines C+2..C+L+1: Line i+C+1 describes a sunscreen lotion bottle i with space-separated integers: SPFi and coveri
Output
A single line with an integer that is the maximum number of cows that can be protected while tanning
Sample Input
3 23 102 51 56 24 1
Sample Output
2
奶牛在沙滩晒太阳,为了不被晒伤,每一头奶牛头给予涂抹防晒霜(sunscreen),每头牛需要涂抹的防晒霜FPS有一个最大值,一个最小值,(FPS,防晒霜级数),有L个篮子,每个篮子里的防晒霜FPS相同,每个篮子里有n瓶防晒霜,每瓶防晒霜只能给一头牛使用,求最多有多少头牛可以很好地去沙滩晒太阳;;;;
#include <iostream>#include <queue>#include <algorithm>#include <stdio.h>#include <string.h>using namespace std;struct node{ int frist,second;};node cow[2505],sec[2505];int C,L;int cmp(node a,node b){ return a.frist<b.frist;}priority_queue<int ,vector<int>,greater<int> >que;///优先队列,从小到大排序int main(){ while(scanf("%d%d",&C,&L)!=-1) { for(int i=0; i<C; i++) scanf("%d%d",&cow[i].frist,&cow[i].second); for(int i=0; i<L; i++) scanf("%d%d",&sec[i].frist,&sec[i].second); sort(cow,cow+C,cmp);///按照奶牛FPS最小值从小到大排序 sort(sec,sec+L,cmp);///按照防晒霜FPS从小到大排序; int k=0,ans=0; for(int i=0; i<L; i++)///以防晒霜顺序查找 { while(k<C&&cow[k].frist<=sec[i].frist)///如果该奶牛min FPS小于 第i个防晒霜FPS { que.push(cow[k].second);///将该奶牛max FPS加入队列 k++; } while(!que.empty()&&sec[i].second) { int t=que.top(); que.pop(); if(t<sec[i].frist)///如果最小的 奶牛 max-FPS小于该防晒霜 就继续 continue; ans++; sec[i].second--; } } printf("%d\n",ans); } return 0;}
- poj3614 priority queue
- priority queue
- stl priority queue
- Priority Queue Version 0.1
- A Priority Queue
- Algorithm episode --priority queue
- Priority Queue 源码分析
- 优先级队列 priority queue
- priority queue 优先队列
- Heap & Priority Queue
- priority queue 优先队列
- Dijkstra with priority queue
- Dijkstra with priority queue
- deck & Priority Queue
- Priority Queue 优先级队列
- Python heap - priority queue
- Tricky Priority Queue
- 优先队列priority queue
- The content of the adapter has changed but ListView did not receive a notification 异常解决方案
- hdu 1162 Eddy's picture
- 多路复用时钟
- 一个简单的天气预报
- Zabbix 2.4 监控 MySQL
- poj3614 priority queue
- 最大连续子序列
- lintcode-BinarySearch-14
- $(function(){})与(function($){})(jQuery)
- zookeeper 分布式锁服务
- 关于运动
- hdu2647 Reward
- [LeedCode OJ]#234 Palindrome Linked List
- 选择排序之堆排序