stormdpzh的专栏

路漫漫其修远兮,吾将上下而求索

poj 3614 Sunscreen

贪心。

/*
Poj: 3614 Sunscreen
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>

#define MaxLC 2505

using namespace std;

struct Cow {
    int minn, maxx;
    
    bool operator < (const struct Cow & t) const {
        return maxx < t.maxx;
    }
}cow[MaxLC];
struct SPF {
    int spf;
    int total;
    
    bool operator < (const struct SPF &t) const {
        if(spf < t.spf)
            return true;
        else
            return false;
    }
}lotion[MaxLC];
int c, l;
int res;

int main()
{
    //freopen("data.in", "rb", stdin);
    while(scanf("%d%d", &c, &l) != EOF) {
        for(int i = 0; i < c; i++) {
            scanf("%d%d", &cow[i].minn, &cow[i].maxx);
        }
        for(int i = 0; i < l; i++) {
            scanf("%d%d", &lotion[i].spf, &lotion[i].total);
        }
        
        sort(cow, cow + c);
        sort(lotion, lotion + l);
        
        res = 0;
        for(int i = 0; i < c; i++) {
            for(int j = 0; j < l; j++) {
                if(lotion[j].spf >= cow[i].minn && lotion[j].spf <= cow[i].maxx && lotion[j].total > 0) {
                    res++;
                    lotion[j].total--;
                    break;
                }
                if(lotion[j].spf > cow[i].maxx)
                    break;
            }
        }
        
        printf("%d\n", res);
    }
    
    return 0;
}


阅读更多
文章标签: struct c
个人分类: poj
上一篇poj 3620 Avoid The Lakes
下一篇poj 3615 Cow Hurdles
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭