标签:style http io ar color os sp for 数据
C小加有一些木棒,它们的长度和质量都已经知道,需要一个机器处理这些木棒,机器开启的时候需要耗费一个单位的时间,如果第i+1个木棒的重量和长度都大于等于第i个处理的木棒,那么将不会耗费时间,否则需要消耗一个单位的时间。因为急着去约会,C小加想在最短的时间内把木棒处理完,你能告诉他应该怎样做吗?
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;
struct st
{
int l,w;
}data[5010];
int cmp(st a,st b)
{
if(a.l!=b.l)
return a.l<b.l;
else
return a.w<b.w;
}
int main()
{
int test,n,i,j,sum,t;
scanf("%d",&test);
while(test--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d %d",&data[i].l,&data[i].w);
sort(data,data+n,cmp);
for(i=0,sum=0;i<n;i++)
{
if(data[i].w!=0)
{
sum++;
t=data[i].w;
for(j=i+1;j<n;j++)
{
if(data[j].w>=t)
{
t=data[j].w;
data[j].w=0;
}
}
}
}
printf("%d\n",sum);
}
return 0;
}
标签:style http io ar color os sp for 数据
原文地址:http://blog.csdn.net/hdd871532887/article/details/41356695