poj3614 贪心
来源:互联网 发布:网络安全法出台的意义 编辑:程序博客网 时间:2024/05/28 11:48
如题:http://poj.org/problem?id=3614
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. Cowi has a minimum and maximum SPF rating (1 ≤ minSPFi ≤ 1,000;minSPFi ≤ maxSPFi ≤ 1,000) that will work. If theSPF 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 bottlei with an SPF rating SPFi (1 ≤SPFi ≤ 1,000). Lotion bottlei 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 bottlei with space-separated integers: SPFi andcoveri
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
Source
题目大意:有C头牛,L种防晒霜,每头牛给出可以忍受的光强区间,每种防晒霜给出可以使牛的光强固定的值和这种防晒霜的数量,默认一开始光强无限大,问使用防晒霜后最多使几头牛能好好晒太阳。
思路:容易想到贪心策略,先对牛的最低限度从小到大排序,对防晒霜每一种的固定光强从小到大排序,遍历防晒霜的同时,维护一个牛的最大忍受光强小根堆,保证最优策略。
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
struct node
{
int min,max;
};
node cow[2505];
struct node1
{
int spf,cover;
};
node1 lotion[2505];
int cmp(node &a,node &b)
{
return a.min<b.min;
}
int cmp1(node1 &a,node1 &b)
{
return a.spf<b.spf;
}
int main()
{
int C,L;
cin>>C>>L;
int i;
for(i=1;i<=C;i++)
scanf("%d%d",&cow[i].min,&cow[i].max);
for(i=1;i<=L;i++)
scanf("%d%d",&lotion[i].spf,&lotion[i].cover);
sort(cow+1,cow+1+C,cmp);
sort(lotion+1,lotion+1+L,cmp1);
priority_queue<int,vector<int>,greater<int>>que;
int res=0;
int j=1;
for(i=1;i<=L;i++)
{
while(j<=C&&cow[j].min<=lotion[i].spf)
{
que.push(cow[j].max);
j++;
}
while(!que.empty()&&lotion[i].cover)
{
int t=que.top();
que.pop();
if(t>=lotion[i].spf)
{
res++;
lotion[i].cover--;
}
}
}
printf("%d\n",res);
}
- poj3614 贪心
- poj3614-贪心、优先队列
- POJ3614 Sunscreen 【贪心】
- POJ3614 贪心 堆
- poj3614 Sunscreen 贪心+单调队列
- poj3614 Sunscreen 贪心 优先队列
- [POJ3614]Sunscreen[贪心][优先队列]
- [优先队列+贪心]poj3614 Sunscreen
- poj3614
- poj3614
- poj3614
- poj3614
- poj3614
- poj3614
- POJ3614
- POJ3614
- poj3614
- poj3614
- View的遍历刷新过程概述
- Odoo(OpenERP)开发实践:菜单隐藏(2)
- 博客搬家 备份
- 第四讲c语言程序初体验——项目二:<1>长方形的周长和面积;<2>电阻并联;<3>温度单位转换
- http协议
- poj3614 贪心
- poj1050
- Android 将Activity及其他类打包成jar包供第三方调用
- 二分图一•二分图判定+异或运算
- Vim 编辑器 初学(2)
- 八大排序算法
- Ubuntu 14.04/14.10下风扇高速旋转解决
- protobuf-net
- Android开发指南(41) —— Searchable Configuration