poj 3614

那么将奶牛按照阳光强度的最小值从小到大排序。

将防晒霜也按照能固定的阳光强度从小到大排序

从最小的防晒霜枚举,将所有符合  minSPF 小于等于该防晒霜的SPF 的奶牛 放入优先队列之中。

然后优先队列是小值先出

所以就可以将优先队列最大值 大于等于 防晒霜的SPF的取出来。

AC代码:

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <map>
#include <vector>
#include <queue>
#define MAXN 2555
#define INF 1000000007
using namespace std;
int C, L;
typedef pair<int, int> P;
priority_queue<int, vector<int>, greater<int> > q;
P cow[MAXN], bot[MAXN];
int main()
{
    scanf("%d%d", &C, &L);
    for(int i = 0; i < C; i++) scanf("%d%d", &cow[i].first, &cow[i].second);
    for(int i = 0; i < L; i++) scanf("%d%d", &bot[i].first, &bot[i].second);
    sort(cow, cow + C);
    sort(bot, bot + L);
    int j = 0, ans = 0;
    for(int i = 0; i < L; i++)
    {
        while(j < C && cow[j].first <= bot[i].first)
        {
            q.push(cow[j].second);
            j++;
        }
        while(!q.empty() && bot[i].second)
        {
            int x = q.top();
            q.pop();
            if(x < bot[i].first) continue;
            ans++;
            bot[i].second--;
        }
    }
    printf("%d\n", ans);
    return 0;
}


谁能告诉我下面的代码为啥是WA?不胜感谢

#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

const int MAX = 2505;

typedef pair<int, int> P;

priority_queue<int, vector<int>, greater<int> > que;

int c, l;

P cow[MAX], bot[MAX];

int main() {
	
	scanf("%d%d", &c, &l);
	for(int i=0; i<c; i++)
		scanf("%d%d", &cow[i].first, &cow[i].second);
	for(int i=0; i<l; i++)
		scanf("%d%d", &bot[i].first, &bot[i].second);
	sort(cow, cow+c);
	sort(bot, bot+l);
	
	int j=0, ans = 0;
	for(int i=0; i<l; i++) {
		while(j < c && cow[i].first <= bot[i].first) {
			que.push(cow[j].second);
			j++;
		}
		while(!que.empty() && bot[i].second) {
			int x = que.top();
			que.pop();
			if(x < bot[i].first)	continue;
			ans++;
			bot[i].second--;
		}
	}
	
	printf("%d\n", ans);	
	return 0;
}




posted @ 2016-09-26 14:00  StevenLuke  阅读(165)  评论(0编辑  收藏  举报