C++56分求助
查看原帖
C++56分求助
683531
zyc232008楼主2023/4/2 20:59
#include<bits/stdc++.h>
using namespace std;
struct times{
	long long time1;
	long long time2;
}p[10000];
long long cmp(struct times a,struct times b){
	if(a.time2 < b.time2){
		return 1;
	}else{
		return 0;
	}
}
long long k,cnt;
long long s = 0;
int main(){
	cin >> k;
	for(int i = 0;i < k;i++){
		cin >> p[i].time1 >> p[i].time2;
	}
	sort(p,p+k,cmp);
	//for(int i = 0;i < k;i++){
	//	cout << p[i].time1 << " " << p[i].time2	 << endl;
	//}
	
	for(int i = 0;i < k;i++){
		if(s <= p[i+1].time1){
			s = p[i+1].time2;
			cnt++;
		}
		
	}
	cout << cnt;
	return 0;
}
/*3
0 2
2 4
1 3*/
2023/4/2 20:59
加载中...