POJ 3614 Sunscreen

Sunscreen

Time Limit: 1000MS Memory Limit: 65536K

Description

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 ≤ SPFi ≤ 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?

Input

  • 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

Output

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

Sample Input

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

Sample Output

2

思路:

本题是一道有限队列的题目,简单的说,乳液的spf要在奶牛的最大的spf和最小的spf之间,首先排序,将奶牛按照最小的spf从小到大排序,乳液按照spf从小到大,然后开始循环,因为之前将奶牛最小的spf从小到大排序了,那么假如奶牛的最小的spf会小于乳液的spf那么,无论后面那种乳液的spf都会符合大于最小spf这个条件,因此就可以将这只奶牛存进优先队列,然后优先队列根据奶牛的 最大的spf从小到大排序,因为小的若是符合,那么大的一定符合,但是小的不符合的情况,那么大的可能可以符合,所以为了是数量最大,那么肯定小的优先,先把难符合条件的先用了,需要注意的是乳液是有数量的,每次用完一瓶,数量要减一(代码虽然长,但是实际真正为核心的就在for循环里面的,并不难理解)。

#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
struct COW {
	int maxn;
	int minn;
};
struct Sunscreen {
	int num;
	int spf;
};
COW cow[2510];
Sunscreen sunscreen[2510];
bool cmp1(COW a, COW b) {
	return a.minn < b.minn;
}
bool cmp2(Sunscreen a, Sunscreen b) {
	return a.spf < b.spf;
}
int main() {
	int C, L;
	cin >> C >> L;
	for (int i = 0; i < C; i++) cin >> cow[i].minn >> cow[i].maxn;
	for (int i = 0; i < L; i++) cin >> sunscreen[i].spf >> sunscreen[i].num;
	sort(cow, cow + C, cmp1);
	sort(sunscreen, sunscreen + L, cmp2);
	int cnt = 0, ans = 0;
	priority_queue<int, vector<int>, greater<int> > q;
	for (int i = 0; i < L; i++) {
		while (cnt < C && cow[cnt].minn <= sunscreen[i].spf) {
			q.push(cow[cnt].maxn);
			cnt++; 
		} 
		while (!q.empty() && sunscreen[i].num) {
			int x = q.top();
			q.pop();
			if (x >= sunscreen[i].spf) {
				sunscreen[i].num--;
				ans++; 
			}
		}
	}
	cout << ans << endl;
	return 0;
} 
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 、4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、下载 4使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、 4下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值