样例过了, 但0分
查看原帖
样例过了, 但0分
1023461
Nian_Gao楼主2023/8/24 20:53
#include<iostream>
#include<algorithm>

using namespace std;

int n, l, ans;
struct node{
	int begin;int end;
}t[1000010]; 
bool cmp(node a, node b){
	return a.begin < b.begin;
}
int main(){
	
	cin >> n; 
	for(int i = 1;i <= n;i++){
		cin >> t[i].begin >> t[i].end;
	}
	sort(t + 1, t + n + 1, cmp);
	l = t[1].end;
	for(int i = 1;i <= n;i++){
		if(t[i].end > l){
			ans++;
			l = t[i].end;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}
2023/8/24 20:53
加载中...