HDU 1051 Wooden Sticks

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1051

#include <iostream>
#include <algorithm>
using namespace std;
struct wooden
{
    int len;
    int weg;
};
wooden wd[5005];
bool cmp1(const wooden &a,const wooden &b)
{
    if(a.len==b.len) return a.weg<b.weg;
    else return a.len<b.len;
}

bool f[5005];
int main()
{
    int i,j,k,T,n;
    cin>>T;
    for(k=0;k<T;k++)
    {
        cin>>n;
        for(i=0;i<n;i++)
            cin>>wd[i].len>>wd[i].weg;
        sort(wd,wd+n,cmp1);
        int ans=0;
        memset(f,0,sizeof(f));
        for(i=0;i<n;i++)
        {
            int weg=wd[i].weg;
            if(f[i]) continue;
                for(j=i+1;j<n;j++)
                {
                    if(f[j]) continue;
                    if(wd[j].weg>=weg)
                    {
                        f[j]=1;
                        weg=wd[j].weg;
                    }
                }
                ++ans;
        }

        cout<<ans<<endl;
    }
    return 0;
}

 

posted @ 2013-09-19 14:53  Destino74  阅读(134)  评论(0编辑  收藏  举报