50分求助
查看原帖
50分求助
1020306
fans_codingfxc楼主2024/5/31 14:06
#include<bits/stdc++.h>
using namespace std;
int com,ans;
bool vis[100005],flag;
struct game{
	int begin;
	int end;
}games[100005];
bool cmp(game x,game y){
	if(x.end==y.end) return x.begin>y.begin;
	return x.end<y.end;
}
int main(){
	cin>>com;
	for(int i=1;i<=com;i++) cin>>games[i].begin>>games[i].end;
	sort(games+1,games+com+1,cmp);
	for(int i=1;i<=com;i++) {
		for(int j=games[i].begin;j<games[i].end;j++)
			if(vis[j]==1) {
				flag=1;
				break;
			}
		if(flag) {
			flag=0;
			continue;
		}
		ans++;
		for(int j=games[i].begin;j<games[i].end;j++) vis[j]=1;	
	}
	cout<<ans;
	return 0;
}
2024/5/31 14:06
加载中...