目录

每日一题洛谷P1803-凌乱的yyy-线段覆盖c

目录

每日一题洛谷P1803 凌乱的yyy / 线段覆盖c++

https://i-blog.csdnimg.cn/direct/1f51f13e34804a2b9f63c792bdce1c23.png

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct time {
	int begin;
	int end;
};
bool com(struct time a, struct time b) {
	return a.end < b.end;
}
int main() {
	int n;
	cin >> n;
	vector<struct time> s(n);
	for (int i = 0; i < n; i++)cin >> s[i].begin >> s[i].end;
	sort(s.begin(), s.end(), com);
	int count = 1;
	int t = s[0].end;
	for (int i = 0; i < n - 1; i++) {
		if (s[i+1].begin >= t) {
			count++;
			t = s[i + 1].end;
		}
	}
	cout << count << endl;
	return 0;
}

https://i-blog.csdnimg.cn/direct/d57bb5c27515480aab2de9cd1fc8495b.png

https://i-blog.csdnimg.cn/direct/cc57ab8d7d514be4934294df2091d814.gif

https://i-blog.csdnimg.cn/direct/dfe62b313cea4c8eb86a927346f2279b.jpeg