标签:
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
typedef struct
{
int length;
int weight;
}stick;
bool cmp(stick x,stick y)
{
if(x.length<y.length)
return true;
if(x.length==y.length&&x.weight<y.weight)
return true;
return false;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int count=0,i,j,n,t;
scanf("%d",&n);
stick a[n];
memset(a,0,sizeof(a));
for(i=0;i<n;i++)
scanf("%d%d",&a[i].length,&a[i].weight);
sort(a,a+n,cmp);
for(i=0;i<n;i++)
printf("%d%d\n",a[i].length,a[i].weight);
for(i=0;i<n;i++)
{
if(a[i].weight!=0)
{
t=a[i].weight;
count++;
for(j=i+1;j<n;j++)
{
if(a[j].weight>=t)
{
t=a[j].weight;
a[j].weight=0;
}
}
}
}
printf("%d\n",count);
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/bailuweishuang520/article/details/47274345