NYOJ 287 Rader

版权声明:欢迎转载!拒绝抄袭. https://blog.csdn.net/qq_36257146/article/details/89814935
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

struct Node{
    int a,b;
    Node(int i,int j):a(i),b(j){}
    bool operator < (const Node & c) const {
        return b<c.b;
    }
};

vector<Node>nodes;

int main()
{
    int n;
    int a,b;
    while(cin>>n){
        nodes.clear();
        for(int i = 0;i<n;i++){
            cin>>a>>b;
            nodes.push_back(Node(a,b));
        }
        sort(nodes.begin(),nodes.end());
        int ans = 1;
        int i = 1;
        int last = nodes[0].b;
        while(i<n){
            if(nodes[i].a>last){
                ans++;
                last = nodes[i].b;
            }
            i++;
        }
        cout<<ans<<endl;
    }
    return 0;
}
/**
4
1 5
2 4
1 4
2 3
3
1 2
3 4
5 6
1
2 2
**/

猜你喜欢

转载自blog.csdn.net/qq_36257146/article/details/89814935