poj3614
来源:互联网 发布:谁人知我心可 编辑:程序博客网 时间:2024/06/09 15:44
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
思路:先进行排序,bottle和cow都按从小到大贪心地使用,先bottle从小到大,对于每个bottle,每种最小值满足的cow都压入优先队列,然后在选择使用的过程中,如果这种cow的最大值小于bottle提供的值,则直接出队列,对于可以使用的则进行使用,直到这种bottle用完或者队列未空,如果结束队列不为空,则队列中剩下的牛cow可以在下一轮中进行判断,能否使用下一种bottle。
#include<iostream>#include<stdio.h>#include<queue>#include<algorithm>using namespace std;typedef pair<int,int> P;priority_queue<int, vector<int>, greater<int> >q; //从小到大的优先队列 int c,l;P cow[2505],bottle[2505];int main(){cin>>c>>l;for(int i=0;i<c;i++)cin>>cow[i].first>>cow[i].second;for(int i=0;i<l;i++)cin>>bottle[i].first>>bottle[i].second;sort(cow,cow+c); //cow按最低值升序排序 sort(bottle,bottle+l); //bottle按其值升序排序 int j=0,ans=0; //j代表cow序号 for(int i=0;i<l;i++){while(j<c&&cow[j].first<=bottle[i].first) //把cow最低值小于bottle的值的cow最高值压入队列 {q.push(cow[j].second);j++;}int x;while(!q.empty()&&bottle[i].second) //如果队列中 cow最高值大于等于bottle的值则可以给这头牛使用 {x=q.top();q.pop();if(x<bottle[i].first)continue;ans++;bottle[i].second--;}}cout<<ans<<endl;}
- poj3614
- poj3614
- poj3614
- poj3614
- poj3614
- poj3614
- POJ3614
- POJ3614
- poj3614
- poj3614
- poj3614 贪心
- POJ3614--Sunscreen
- POJ3614-Sunscreen
- POJ3614-number1
- poj3614-贪心、优先队列
- poj3614 Sunscreen 【优先队列】
- POJ3614 Sunscreen 【贪心】
- poj3614 优先队列
- 树的创建、插入
- 文本学习
- 【C#】panel重绘闪烁问题
- Linux文件系统的实现
- 阿里云服务器远程登陆
- poj3614
- HDU5033 building
- Spring(AbstractRoutingDataSource)实现动态数据源切换-- 转载
- simulink小技巧:如何将自己编写的模块集成到模块浏览器里面去
- IoC容器源码-容器的基本用法
- 金融安全期刊01:云战略下的安全思维转型与新认知
- Tensorflow框架下Faster-RCNN实践(一)——Faster-RCNN所需数据集制作(附代码)
- jQuery基础:动态生成表格和绑定事件
- Elasticsearch为记录添加时间戳timestamp