07: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 <= minSPF_i <= 1,000; minSPF_i <= maxSPF_i <= 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 SPF_i (1 <= SPF_i <= 1,000). Lotion bottle i can cover cover_i 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: minSPF_i and maxSPF_i

  • Lines C+2…C+L+1: Line i+C+1 describes a sunscreen lotion bottle i with space-separated integers: SPF_i and cover_i
    输出
    A single line with an integer that is the maximum number of cows that can be protected while tanning
    样例输入
    3 2
    3 10
    2 5
    1 5
    6 2
    4 1
    样例输出
    2
    提示
    INPUT DETAILS:

3 cows; 2 lotions. Cows want SPF ratings of 3…10, 2…5, and 1…5. Lotions available: 6 (for two cows), 4 (for 1 cow). Cow 1 can use the SPF 6 lotion. Either cow 2 or cow 3 can use the SPF 4 lotion. Only 2 cows can be covered.

题意:就是晒牛 让牛变黑但不能让他伤;输入牛的数量 和 防晒霜的数量
然后在输入每个牛的最大和最小的强度,然后输入防晒爽的强度和瓶数,如果强度位于牛的最大和最小之间,那么这个牛就能涂抹;
wronganser思路: 先把牛排队,按照min值来排队,然后再把防晒霜按照强度来排序,之后 按照防晒霜的强度依次来看看能给哪头牛涂。这个思想只考虑到了 一般,难道符合的就一定可以涂抹么?

ac思路还得考虑max的问题,就是防晒霜的强度大于牛的最小值,小于牛的最大值不能直接涂,先把满足牛的max先把它存起来,按照从小到大来存,之后一次涂抹,你要先涂最大值中较小的牛
然后用到了优先队列
priority_queue <data_type> priority_queue_name;
如:priority_queue q;//默认是大顶堆

上边这个是排的最大值

priority_queue<int, vector, greater > q;
这个才是最小值得在栈顶
注意 q.empty()如果队列为空 返回true 反之返回false

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<string>
#include<vector>
using namespace std;
priority_queue<int, vector<int>, greater<int> > q;
struct cow
{
	int high, low;
}c[2600];
struct sp
{
	int f, num;
}s[2600];

int cmp(sp a, sp y)
{
	return a.f < y.f;
}
int cmpp(cow a,cow b)
{
	return a.low<b.low;
	return a.high<b.high;
}
int main()
{
	int n1, n2; cin >> n1 >> n2;
	for (int i = 0; i < n1; i++)
		cin >> c[i].low >> c[i].high; 
	for (int i = 0; i < n2; i++)
		cin >> s[i].f >> s[i].num;
	sort(s, s + n2, cmp); sort(c, c + n1, cmpp); int ans = 0;
	int v = 0;
	for (int i = 0; i <n2; i++)
	{
		while (v<n1 && c[v].low<= s[i].f)
		{
			q.push(c[v].high); v++;
		}
		while (q.empty()==0&&s[i].num>0)
		{
			int t = q.top();
			q.pop();
			if (t>=s[i].f)
			{
				ans++;
				s[i].num--;
			}
			else continue;
		}
	}
	cout << ans;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值