Sunscreen-POJ - 3614
发布日期:2022-02-10 08:11:11 浏览次数:15 分类:技术文章

本文共 2028 字,大约阅读时间需要 6 分钟。

Sunscreen

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; minSPFimaxSPFi ≤ 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

题意:有C头牛和L瓶防晒霜,分别给出C头牛需要防晒霜的范围和L瓶防晒霜的SPF和可用与多少头牛,求有多少头牛能满足要求

解题思路:优先队列和贪心,先将牛按照对防晒霜的最小需求排序,再将防晒霜按从小到大的顺序排序,对于防晒霜i来说肯定给满足条件且maxSPF最小的牛来用最划算,因为后面还有SPF更大的防晒霜,所以如果大于当前牛的minSPF则将该牛加入优先队列,让maxSPF最小的牛先出队,如果该防晒霜满足要求则先给该牛使用。

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define maxn 1000000000using namespace std;typedef long long ll;typedef pair
P;int main(){ int c,l; cin>>c>>l; P cow[2505],bottle[2505]; for(int i=0;i
,greater
>que; //小的数先出队 sort(cow,cow+c); sort(bottle,bottle+l); int cowi,ans; cowi=ans=0; //cowi为牛的序号,ans为满足需求的牛的个数 for(int i=0;i
=cow[cowi].first) que.push(cow[cowi++].second); //maxSPF入队 while(!que.empty()&&bottle[i].second) { int spf=que.top(); que.pop(); if(bottle[i].first>spf) //该防晒霜的SPF大于该牛的maxSPF continue; else { ans++; bottle[i].second--; //对该牛使用一次,次数减少1 } } } cout<

 

转载地址:https://blog.csdn.net/qq_44632981/article/details/98884168 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Find them, Catch them-POJ - 1703-并查集
下一篇:生日蛋糕——POJ1190——DFS+剪枝

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2024年03月28日 17时55分41秒