C

来源:互联网 发布:java希尔排序算法 编辑:程序博客网 时间:2024/06/06 12:45
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#pragma warning(disable:4996)
using namespace std;
struct stick {
int len;
int wei;
}st[10000];
bool sure[5010];
int cmp(stick a, stick b)
{
if (a.len != b.len)
return a.len< b.len;
return b.wei > a.wei;
}
int main()
{
int n,t;
scanf("%d", &t);
while(t--)

scanf("%d", &n);
int i, num = 0,time=0,j;
for (i = 0; i < n; i++)
scanf("%d %d", &st[i].len, &st[i].wei);
sort(st, st + n,cmp);
memset(sure, false, sizeof(sure));
for (i = 0; i < n; i++)
{
if (!sure[i])
{
sure[i] = true;
for (j = i + 1, time = st[i].wei; j < n; j++)
if (st[j].wei >= time && (!sure[j]))
{
time = st[j].wei;
sure[j] = true;
}
num++;
}
}
printf("%d\n",num);
}
return 0;
}
原创粉丝点击