题解
2023-05-27 17:20:51
发布于:上海
15阅读
0回复
0点赞
#include<iostream>
#include<algorithm>
using namespace std;
struct time{
int begin,end;
}a[10005];
int cmp(struct time a1,struct time a2){
if(a1.end!=a2.end)
return a1.end<a2.end;
if(a1.begin!=a2.begin)
return a1.begin<a2.begin;
}
int read(){
int x = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9'){
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9'){
x = x * 10 + (ch - '0');
ch = getchar();
}
return x * w;
}
int main(){
int n,p,m;
cin>>m;
while(m--){
n=read();
for(int i=0;i<n;i++){
a[i].begin=read();
a[i].end=read();
}
sort(a,a+n,cmp);
p=a[0].end;
int count = 1;
for(int i=1;i<n;i++){
if(a[i].begin>p) {
count++;
p=a[i].end;
}
}
printf("%d\n",count);
}
return 0;
}
这里空空如也
有帮助,赞一个