选择不相交区间

http://acm.nyist.net/JudgeOnline/problem.php?pid=14

#include
#include
#include
using namespace std;
struct Node{

    int x,y;
} arr[10010];
bool cmp(const Node &a,const Node &b)
{
    return (a.yb.x));
}
int main()
{
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int n;
            scanf("%d",&n);
            for(int i=1;i<=n;i++)
            {
                scanf("%d%d",&arr[i].x,&arr[i].y);
            }
            sort(arr+1,arr+n+1,cmp);
            int sum=1;
            int dy=arr[1].y;
            for(int i=2;i<=n;i++)
            {
                if(arr[i].x>dy)
                {
                    sum++;
                    dy=arr[i].y;
                }
            }
            printf("%d\n",sum);
        }
}      

你可能感兴趣的:(选择不相交区间)