#include<iostream>
using namespace std;
int start_time[10000], end_time[10000];
int n, sum = 0;
void sort_time(void) {
for (int i = 0;i < n;i++) {
for (int m = 0;m < n;m++) {
if (end_time[m] > end_time[i] && m != i) {
int p = end_time[i];
end_time[i] = end_time[m];
end_time[m] = p;
p = start_time[i];
start_time[i] = start_time[m];
start_time[m] = p;
}
}
}
}
int main() {
cin >> n;
for (int i = 0;i < n;i++) {
cin >> start_time[i] >> end_time[i];
for (int m = 0;m < i;m++) {
if (start_time[i] == start_time[m]) {
if (end_time[i] >= end_time[m]) {
start_time[i] = -1;
end_time[i] = -1;
i--;
n--;
}
else if (end_time[i] < end_time[m]) {
end_time[m] = end_time[i];
start_time[m] = start_time[i];
start_time[i] = -1;
end_time[i] = -1;
i--;
n--;
}
}
}
}
sort_time();
int h = 0;
for (int i = 1;i < n;i++) {
if (start_time[i] >= end_time[h]) {
h = i;
sum++;
}
}
cout << sum+1;
return 0;
}
感觉一开始去掉相同开始时间的步骤有点多此一举,然后排序那里我只会手动排了,用了sort的话我不能保证他的结束时间会一一对应。