POJ 3614 Sunscreen 优先队列

空想没有收获,行动才有收获

#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
priority_queue<P> que;
// mint first,maxt second
queue<P> cows, tmp;
// val first,count second
P bos[2507];
int L, C, ans = 0;
void input()
{
    scanf("%d%d", &C, &L);
    int mint = 0, maxt = 0;
    for (int i = 1; i <= C; i++)
    {
        scanf("%d%d", &mint, &maxt);
        cows.push(P(mint, maxt));
    }
    for (int i = 1; i <= L; i++)
    {
        scanf("%d%d", &bos[i].first, &bos[i].second);
    }
}
void preHandle()
{
    ans = 0;
    sort(bos + 1, bos + 1 + L);
}
void deal(int i)
{
    while (!cows.empty())
    {
        P cow = cows.front();
        cows.pop();
        if (cow.first <= bos[i].first && cow.second >= bos[i].first)
        {
            que.push(cow);
        }
        else
        {
            tmp.push(cow);
        }
    }
    for (int j = 1; j <= bos[i].second && !que.empty(); j++)
    {
        que.pop();
        ans++;
    }
    while (!que.empty())
    {
        cows.push(que.top());
        que.pop();
    }
    while (!tmp.empty())
    {
        cows.push(tmp.front());
        tmp.pop();
    }
}
void solve()
{
    for (int i = L; i >= 1; i--)
    {
        while (!que.empty())
        {
            que.pop();
        }
        while (!tmp.empty())
        {
            tmp.pop();
        }
        deal(i);
    }
}
int main()
{
    input();
    preHandle();
    solve();
    printf("%d\n", ans);
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值