题目:一共C头牛 牛要日光浴,第i头牛 需要的阳光强度 在区间[mini,maxi]之间,因为阳光对一些牛牛来说太强了 因此需要给一些牛牛涂防晒霜,现有L种防晒霜 第i种有coveri瓶 能让阳光强度稳定在SPFi的强度 ,一瓶只能用给一头牛牛 用完之后就被丢弃。问 最多能让多少头牛涂上防晒霜?
思路:将奶牛按照阳光强度最小值从小到大排序,防晒霜也按照阳光强度从小到大进行排序。当奶牛需要阳光强度最小值小于该防晒霜的阳光强度时,将奶牛需要阳光强度最大值放入优先队列之中。将奶牛需要阳光最大强度值与该防晒霜的阳光强度进行比较,如果防晒霜的阳光强度恰好在奶牛需要阳光强度之间,就进行计数。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <map>
#include <vector>
#include <queue>
#define MAXN 2505
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;
}
596

被折叠的 条评论
为什么被折叠?



