矩形嵌套 南工16

来源:互联网 发布:qq飞车飞碟数据 编辑:程序博客网 时间:2024/06/05 15:32

题目链接: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;}