2021-08-27 AcWing 3818. 餐厅_#include

输入样例1:

2
7 11
4 7

输出样例1:

1

输入样例2:

5
1 2
2 3
3 4
4 5
5 6

输出样例2:

3

输入样例3:

6
4 8
1 5
4 7
2 5
1 3
6 8

输出样例3:

2
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 1e6;
/*typedef struct t{
int start;
int end;
}T;
bool cmp(T& x,T& y){
return x.end < y.end;
}*/

typedef struct t{
int start;
int end;
bool operator< (const t& t1) const{
return end<t1.end;
}
}T;
T a[N];
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i ++ )
{
scanf("%d%d", &a[i].start, &a[i].end);
}
sort(a, a+n, cmp);
int cnt = 0;
int last = -1;
for (int i = 0; i < n; i ++ )
{
if(a[i].start>last)
{
cnt++;
last = a[i].end;
}
}
cout << cnt;
return 0;
}