POJ3614-Sunscreen

来源:互联网 发布:做假图软件 编辑:程序博客网 时间:2024/06/16 21:49

每一种防晒霜可以给多个牛使用,这时候该如何决策呢?

维护一个优先队列,按maxSPF从小到大的顺序排列。这是为了尽量把SPF小的防晒霜给maxSPF小的牛。

首先将牛和防晒霜进行排序,然后按防晒霜的SPF从小到大分配给可用的牛。

#include <cstdio>#include <algorithm>#include <functional>#include <queue>using namespace std;typedef pair<int, int> P;const int MAXN = 2500;P cows[MAXN+5];P lot[MAXN+5];priority_queue<int, vector<int>, greater<int> > que;int main(){    int c, l;    scanf("%d%d", &c, &l);        for (int i = 0; i < c; i++)        scanf("%d%d", &cows[i].first, &cows[i].second);    sort(cows, cows + c);    for (int i = 0; i < l; i++)        scanf("%d%d", &lot[i].first, &lot[i].second);    sort(lot, lot + l);        int res = 0;    int j = 0;    for (int i = 0; i < l; i++) {        while (j < c && cows[j].first <= lot[i].first) {            que.push(cows[j].second);            j++;        }        while (!que.empty() && lot[i].second) {            int cow = que.top();            que.pop();            if (cow >= lot[i].first) {                lot[i].second--;                res++;            }        }    }    printf("%d\n", res);        return 0;}


0 0