POJ 3614 Sunscreen G++ 枚举没实现 优先队列实现 贪心 背


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
using namespace std;
//英语 看博友分析 抄博友程序 枚举没实现 优先队列实现 贪心  背 
struct cow{
	int l;
	int r;
}; 
bool cmp1(cow a,cow b)
{
	return a.l<b.l;	
}
struct lot{
	int zhi;
	int num;
};
bool cmp2(lot a,lot b)
{
	return a.zhi<b.zhi;
}
int main()
{
	int n,m;
	cin>>n>>m;
	vector<cow> da;
	for(int i=0;i<n;i++)
	{
		cow t;
		cin>>t.l>>t.r;
		da.push_back(t);
	} 
	sort(da.begin(),da.end(),cmp1);
	vector<lot> ve;
	for(int i=0;i<m;i++)
	{
		lot t;
		cin>>t.zhi>>t.num;
		ve.push_back(t);
	}
	sort(ve.begin(),ve.end(),cmp2);
	priority_queue<int,vector<int>,greater<int> > que;//必须是优先队列  不漏牛 
	int j=0;//牛 
	int jg=0;
	for(int i=0;i<ve.size();i++)//枚举防嗮霜
	{
		while(j<da.size() && ve[i].zhi>=da[j].l)//有条件 
		{
			que.push(da[j].r);
			j++;
		} 
		while(que.empty()!=1 && ve[i].num>0)
		{
			int t=que.top();
			que.pop();
			if(t>=ve[i].zhi)
			{
				jg++;
				ve[i].num--;
			}
		}
	}
	cout<<jg<<endl;
	return 0;
}

 



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值