[贪心] [STL] [51nod] 做任务三

按左点排序

能干就干 干不了加人

但这次数据非常大 手动模拟超时

需要用到优先队列 或 mutilset

队列能解决的set 都可以解决

set支持性更佳 所以个人更倾向于set

#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

const int MAXN = 1e5 + 10;

int M, N, T;

struct miss
{
	int beg, end;

}arr[MAXN];

bool cmp(miss a, miss b)
{
	if(a.beg != b.beg)
			return a.beg < b.beg;
	return a.end < b.end;
}

int main()
{
	cin>>T;

	while(T--)
	{
		multiset <int> pep;
		
		pep.clear();

		cin>>M>>N;

		for(int i = 0; i < M; i++)
		{
			cin>>arr[i].beg>>arr[i].end;
		}

		sort(arr, arr + M, cmp);

		for(int i = 0; i < M; i++)
		{
			if( pep.size() && *pep.begin() <= arr[i].beg) //set自动升序
			{
				pep.erase(--pep.upper_bound(arr[i].beg)); //upper 是 < --符合题意

				pep.insert(arr[i].end); //插入
			}
			else
			{
				pep.insert(arr[i].end); //插入
			}
		}

		cout<<pep.size()<<endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/zeolim/article/details/81188117
今日推荐