@[Tapper](/user/843596) if 错了,可以定义 `back`
```cpp
if(back<=nodes[i].back){
back=nodes[i].back;
count++;
}
```
by Light_az @ 2022-12-17 09:26:49
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
struct node
{
int head;
int back;
} nodes[N];
bool com(node a, node b)
{
return a.back < b.back;
}
int main()
{
int total;
cin >> total;
for (int i = 0; i < total; i++)
{
cin >> nodes[i].head >> nodes[i].back;
}
int count = 1;
sort(nodes, nodes + total, com);
int end=nodes[0].back;
for (int i = 1; i < total; i++)
{
if (end<=nodes[i].head)
{
count++;
end=nodes[i].back;
}
}
cout << count << endl;
return 0;
}
```
@[Tapper](/user/843596)
by Light_az @ 2022-12-17 09:30:45
@[lianzhuo](/user/654958) 哦对对,应该做一个now_back记录此时back到哪里了,然后用后面的head和now_back比较,明白了明白了,谢谢大佬哇!!!
by Otion @ 2022-12-17 09:30:59
@[lianzhuo](/user/654958) 经过大犇的指点AC啦
```
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
struct node
{
int head;
int back;
} nodes[N];
bool com(node a, node b)
{
return a.back < b.back;
}
int main()
{
int total;
cin >> total;
for (int i = 0; i < total; i++)
{
cin >> nodes[i].head >> nodes[i].back;
}
int count = 1;
sort(nodes, nodes + total, com);
int now_back = nodes[0].back;
for (int i = 1; i < total; i++)
{
if (now_back <= nodes[i].head)
{
count++;
now_back = nodes[i].back;
}
}
cout << count << endl;
return 0;
}
```
by Otion @ 2022-12-17 09:32:18
~~那你就关注我吧~~ QwQ
by Light_az @ 2022-12-17 09:33:44
@[lianzhuo](/user/654958) 哈哈哈一定一定
by Otion @ 2022-12-17 09:34:23