[USACO2007NOVG] Sunscreen

题目描述

To avoid unsightly burns while tanning, each of the$ C (1 ≤ C ≤ 2500) $cows must cover her hide with sunscreen when they're at the beach. Cow i has a minimum and maximum SPF rating (1 ≤ minSPFi ≤ 1,000; minSPFi ≤ maxSPFi ≤ 1,000) that will work. If the SPF rating is too low, the cow suffers sunburn; if the SPF rating is too high, the cow doesn't tan at all........

The cows have a picnic basket with \(L (1 ≤ L ≤ 2500)\) bottles of sunscreen lotion, each bottle i with an SPF rating SPFi (\(1 ≤ SPF_i ≤ 1,000\)). Lotion bottle i can cover coveri cows with lotion. A cow may lotion from only one bottle.

What is the maximum number of cows that can protect themselves while tanning given the available lotions?

输入格式

* Line 1: Two space-separated integers: C and L

* Lines 2..C+1: Line i describes cow i's lotion requires with two integers: minSPFi and maxSPFi

* Lines C+2..C+L+1: Line i+C+1 describes a sunscreen lotion bottle i with space-separated integers: SPFi and coveri

输出格式

A single line with an integer that is the maximum number of cows that can be protected while tanning

样例 #1

样例输入 #1

3 2
3 10
2 5
1 5
6 2
4 1

样例输出 #1

2

简化一下题意:给出很多个区间和点,一个区间和一个点匹配,要求点在区间内。
既然是匹配,可以考虑二分图匹配。但是太过麻烦了。
把所有的区间按照右端点从小到大虑选择最靠左的没被选的数。因为右区间没到的问题越到后面越不用考虑。那么左端点能选的就赶紧选了。

#include<bits/stdc++.h>
using namespace std;
const int N=2505;
struct node{
	int l,r;
	bool operator<(const node&n)const{
		return r<n.r;
	}
}d[N];
struct dian{
	int x,y;
	bool operator<(const dian&n)const{
		return x<n.x;
	}
}a[N];
int c,l,t,cnt;
int main()
{
	scanf("%d%d",&c,&l);
	for(int i=1;i<=c;i++)
		scanf("%d%d",&d[i].l,&d[i].r);
	for(int i=1;i<=l;i++)
		scanf("%d%d",&a[i].x,&a[i].y);
	sort(d+1,d+c+1);
	sort(a+1,a+l+1);
	for(int i=1;i<=c;i++)
		for(int j=1;j<=l;j++)
			if(a[j].y&&a[j].x>=d[i].l&&a[j].x<=d[i].r)
				++cnt,a[j].y--,j=l; 
	printf("%d",cnt);
	return 0;
}
···
posted @ 2022-06-02 17:45  灰鲭鲨  阅读(76)  评论(0)    收藏  举报