1 solutions

  • 0
    @ 2025-11-5 17:01:13

    C++ :

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    struct fun
    {
        int length;
        int weight;
    } s[5010];
    int cmp(fun a,fun b)
    {
        if(a.length!=b.length)
            return a.length<b.length;
        else
            return a.weight<b.weight;
    }
    int main()
    {
        int n,m,count,end,j;
        //freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        cin>>n;
        while(n--)
        {
            count=0;
            cin>>m;
            for(int i=0; i<m; i++)
                cin>>s[i].length>>s[i].weight;
            sort(s,s+m,cmp);
            for(int i=0; i<m; i++)
            {
                end=s[i].weight;
                if(s[i].weight!=0)
                {
                    for(j=i+1; j<m; j++)
                        if(s[j].weight>=end)
                        {
                            end=s[j].weight;
                            s[j].weight=0;
                        }
                    count++;
                }
    
            }
            cout<<count<<endl;
        }
    }
    
    
    • 1

    Information

    ID
    18156
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By