LibreOJ #10000. 「一本通 1.1 例 1」活动安排 题解

原题地址

我谔谔,在看题目的时候突然发现:
这tm好像就是这一题
于是就AC了
经典的贪心线段覆盖题目
C o d e \color{blue}Code

# include <bits/stdc++.h>
using namespace std;
int n;
struct node
{
	int s,t;
}a[1010];
bool cmp(struct node x,struct node b) 
{
	return x.t<=b.t;
}
int main(void) 
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i].s,&a[i].t);
	}
	sort(a+1,a+n+1,cmp);
	int tot=0,lst=1;
	for(int i=1;i<=n;i++)
	{
		if(lst<=a[i].s)
		{
			tot++;
			lst=a[i].t;
		}
	}
	cout << tot << endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/woshidalaocxy/article/details/105497369