贪心入门,蒟蒻看不出错误呜呜呜,样例都没过
查看原帖
贪心入门,蒟蒻看不出错误呜呜呜,样例都没过
843596
Otion楼主2022/12/17 09:23
#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);
    for (int i = 1; i < total; i++)
    {
        if (nodes[i - 1].back <= nodes[i].head)
        {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}
2022/12/17 09:23
加载中...