NYOJ 会场安排问题

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
struct HY
{
    int u,v;
}hy[10005];
bool cmp(HY a,HY b)
{
    if(a.v == b.v)    return a.u>b.u;    
    else            return a.v<b.v;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        for(int i=0;i<n;i++)
        {
            scanf("%d %d",&hy[i].u,&hy[i].v);
        }
        sort(hy,hy+n,cmp);
        int begin=-1,end=-1,cnt=0;
        for(int i=0;i<n;i++)
        {
            if(i!=0)
            {
                if(hy[i].u>end)
                {
                    end = hy[i].v;
                    cnt++;
                }
            }
            else
            {
                end = hy[i].v;
                cnt++;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
} 

猜你喜欢

转载自www.cnblogs.com/fzuhyj/p/9833207.html