矩形嵌套 南工16

题目链接:here~~

先排序再求才AC了


#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
struct cd
{
    int x, y;
    bool operator < (cd r)const
    {
        if (x==r.x)
            return y<r.y;
        else
            return x<r.x;
    }
}a[1001];
int res[1001];
int main()
{
    int n, m, i, j, max, t;
//    freopen("in.txt", "r", stdin);
    scanf("%d", &n);
    while (n--)
    {
        cin>>m;
        memset(a, 0, sizeof(a));
        memset(res, 0, sizeof(res));
        for (i = 0; i<m; i++)
        {
            cin>>a[i].x>>a[i].y;
            if (a[i].x>a[i].y)
            {
                t = a[i].x;
                a[i].x=a[i].y;
                a[i].y=t;
            }
        }
        sort(a, a+m);
        for (i=0; i<m; i++)
        {
            if (i==0)
            {
                res[i]=1;
                continue;
            }
            max = 0;
            for (j = 0; j<i; j++)
            {
                if (a[i].x>a[j].x&&a[i].y>a[j].y&&max<res[j])
                    max = res[j];
            }
            res[i]=max+1;
        }
        max = 0;
        for (i=0; i<m; i++)
        {
            if (max<res[i])
                max=res[i];
  //          cout<<res[i]<<" "<<a[i].x<<" "<<a[i].y<<endl;
        }
        cout<<max<<endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值