[POJ3614]Sunscreen[贪心][优先队列]

题目链接:[POJ3614]Sunscreen[贪心][优先队列]

题意分析:牛牛们想要晒日光浴,可是紫外线太毒,现在有L种防晒霜,每瓶能敷SPFi的值,有COVERi瓶,牛牛们有个可接受的防晒霜范围,太少没效果,太多就不能晒日光浴了,而每次必须把一瓶的容量都涂上去,问:最多能涂多少只牛呢?

解题思路:将防晒霜按容量从小到大排序,将牛牛们可接受的最小敷值从小到大排序。每次循环找出能被敷上的牛放入优先队列。

个人感受:一直没读懂题意。。。。没理解那句:超过敷值就等于没有晒太阳。。。。样例都看不懂,智商捉急。。。。TAT

具体代码如下:

#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

const int MAXN = 3000;
priority_queue<int, vector<int>, greater<int> > pq; //这里使用优先队列存储spf的最大值,最大值小的在前面
typedef pair<int, int> P;
P cow[MAXN], bot[MAXN];

int main() {
    ios_base::sync_with_stdio(0);
    int c, l;
    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 >> bot[i].first >> bot[i].second;
    sort(cow, cow + c), sort(bot, bot + l);
    int num = 0, ans = 0;
    for (int i = 0; i < l; ++i)
    {
        while (num < c && cow[num].first <= bot[i].first) //bot[i]能敷上的牛
        {
            pq.push(cow[num].second);
            ++num;
        }
        while (!pq.empty() && bot[i].second)
        {
            int tem = pq.top(); pq.pop(); //优先把最大值小的敷掉~
            if (tem < bot[i].first) continue;//由于bot从小到大排序,它敷不了的,其它也敷不了
            ++ans;
            bot[i].second--;
        }
    }
    cout << ans << '\n';
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值