码迷,mamicode.com
首页 > 其他好文 > 详细

心急的C小加

时间:2015-08-04 13:38:34      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:




#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);
    }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

心急的C小加

标签:

原文地址:http://blog.csdn.net/bailuweishuang520/article/details/47274345

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!