本文共 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; 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 coveriOutput
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
转载地址:https://blog.csdn.net/qq_44632981/article/details/98884168 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!