1048: Wooden Sticks

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct Node
{
    int len;
    int wei;
};
Node a[21000];
int f[210000];
bool cmp(Node x,Node y)
{
    if(x.len!=y.len) return x.len<y.len;
    return x.wei<y.wei;
}
int main()
{
    int ci;scanf("%d",&ci);
    while(ci--)
    {
        int n;scanf("%d",&n);
        for(int i=0;i<n;i++) scanf("%d%d",&a[i].len,&a[i].wei);
        sort(a,a+n,cmp);
        int cnt=1;
        f[1]=a[0].wei;
        for(int i=0;i<n;i++)
        {
            int p=0;
            for(int j=1;j<=cnt;j++)
            {
                if(f[j]<=a[i].wei&&f[j]>f[p])
                {
                    p=j;
                }
            }
            if(p==0)
            {
                cnt++;
                f[cnt]=a[i].wei;
            }
            else
            {
                f[p]=a[i].wei;
            }
        }
        printf("%d/n",cnt);
    }
    return 0;
}

你可能感兴趣的:(ini)