标签:
3 5 4 9 5 2 2 1 3 5 1 4 3 2 2 1 1 2 2 3 1 3 2 2 3 1
2 1 3
#include <stdio.h>
#include <algorithm>
using namespace std;
//1051
typedef struct node
{
int x,y,isUsed;
}NODE;
int cmp(NODE a, NODE b)
{
//如果x相同,就按y降序排序
if (a.x == b.x)
{
return a.y>b.y;
}
else
{
return a.x>b.x;
}
}
int main()
{
int T,N;
NODE c[5001];
while (scanf("%d", &T)!=EOF)
{
while (T--)
{
scanf("%d", &N);
for (int i=0; i<N; i++)
{
scanf("%d %d", &c[i].x, &c[i].y);
c[i].isUsed = 0;
}
sort(c, c+N, cmp);
int time = 0;
for (int i=0; i<N; i++)
{
if (c[i].isUsed == 1)
continue;
int x,y;
x = c[i].x; y = c[i].y;
//标记当前为用过了
c[i].isUsed = 1;
for (int j=i+1; j<N; j++)
{
if (c[j].x<=x && c[j].y<=y && c[j].isUsed == 0)
{
x = c[j].x;
y = c[j].y;
c[j].isUsed = 1;
}
}
time++;
}
printf("%d\n", time);
}
}
return 0;
}
标签:
原文地址:http://blog.csdn.net/a237653639/article/details/46407787