poj3614 Sunscreen 【优先队列】

题意

有C个奶牛去晒太阳 (1 <=C <= 2500),每个奶牛各自能够忍受的阳光强度有一个最小值和一个最大值,太大就晒伤了,太小奶牛没感觉。

而刚开始的阳光的强度非常大,奶牛都承受不住,然后奶牛就得涂抹防晒霜,防晒霜的作用是让阳光照在身上的阳光强度固定为某个值。

那么为了不让奶牛烫伤,又不会没有效果。

给出了L种防晒霜。每种的数量和固定的阳光强度也给出来了

每个奶牛只能抹一瓶防晒霜,最后问能够享受晒太阳的奶牛有几个。

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

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

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

然后优先队列是小值先出

所以就可以将这些最大值中的最小的取出来。更新答案。

注意priority_queue的声明priority_queue<int, vector<int>, greater<int> > que;

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
const int Max = 11111;
priority_queue<int, vector<int>, greater<int> > que;
struct eg
{
	int x,y;
}cow[Max],bot[Max];
bool cmp(const eg& a,const eg& b)
{
	return a.x<b.x;
}
int main()
{
	#ifndef ONLINE_JUDGE
		freopen("G:/1.txt","r",stdin);
		freopen("G:/2.txt","w",stdout);
	#endif
	int C,L;
	scanf("%d%d",&C,&L);
	for(int i=0;i<C;i++)
		scanf("%d%d",&cow[i].x,&cow[i].y);
	for(int i=0;i<L;i++)
		scanf("%d%d",&bot[i].x,&bot[i].y);
	sort(cow,cow+C,cmp);
	sort(bot,bot+L,cmp);
	int ans=0,j=0;
	for(int i=0;i<L;i++)
	{
        while(j<C&&cow[j].x<=bot[i].x)//j牛的最小太阳量小于i防晒霜的固定量
		{
			que.push(cow[j].y);
			j++;
		}
		while(!que.empty()&&bot[i].y)
		{
			int x=que.top();
			que.pop();
			if(x<bot[i].x)
				continue;
			ans++;
			bot[i].y--;
		}
	}
	printf("%d\n",ans);
	return 0;
}

poj3614 Sunscreen 【优先队列】

时间: 2024-08-29 14:35:44

poj3614 Sunscreen 【优先队列】的相关文章

POJ 3614 Sunscreen 优先队列

http://poj.org/problem?id=3614 题目大意: 给你一些母牛,母牛有能容忍日光浴的最小和最大光照强度.每仅仅母牛能够涂一次SPF,SPF能够将母牛能够承受的光照强度固定在某个地方.如今给你母牛的最小和最大值和不同的spf的光照强度及其数量,求最多能够有多少母牛享受日光浴? 思路: 优先队列. 先按母牛最小承受的排好,然后spf的值也从小到大. 接下来用优先队列(栈顶为最小的).对于每一个spf,假设一仅仅母牛的最小值小于等于spf则将其最大值入队.(贪心..如两个母牛一

poj 3614 Sunscreen(优先队列+贪心)

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 w

POJ No 3614 Sunscreen 优先队列 贪心

Sunscreen Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6410   Accepted: 2239 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

POJ3614 Sunscreen 【贪心】

Sunscreen Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4204   Accepted: 1458 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

poj3614 Sunscreen【贪心】

Sunscreen Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11772   Accepted: 4143 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 ha

POJ3614 Sunscreen 贪心入门

题目大意 给出一些区间和一些点,一个点如果在一个区间内,那么此两者可以匹配.问匹配数最大是多少. 题解 这样的题我们一般都是站在区间上去找与其配对的点.我们可以得到如下性质: 对于一段区间\([l_1,r_1]\)的任意两点\(a,b, a<b\),它们对于任意一个区间\([l_2,r_2],l_2<l_1\),\(a\in[l_2,r_2]\)的可能性(以后用P表示)\(P(a\in[l_2,r_2])>P(b\in[l_2,r_2])\). 什么叫"可能性大"呢?

Sunscreen(POJ 3614 优先队列)

Sunscreen Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5898   Accepted: 2068 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

贪心+优先队列 POJ3614

m头牛每头牛有minspf和maxspf,n种spf为spf[i]的防晒霜每种l[i]瓶,尽可能给数量多的牛涂防晒霜,每头牛最多涂一瓶. 贪心想法后,实现是每次取出minspf<=spf[i]的牛加入优先队列中,优先队列以牛的maxspf为优先,给maxspf>=spf[i]且maxspf从小开始取的牛涂(优先队列). #include<cstdio> #include<iostream> #include<algorithm> #include<qu

Sunscreen (poj 3614 贪心+优先队列)

Language: Default Sunscreen Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4499   Accepted: 1565 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 th