10131 - Is Bigger Smarter?

描述:题意很简单,先快排一下,然后从中选择即可,因为我觉得只用数组有些麻烦,所以用了结构体
#include <cstdio>
#include <cstdlib>
struct Ele
{
    int We;
    int Iq;
    int sum;
    int next;
    int pos;
};
Ele count[1010];
int cmp(const void *p1 ,const void *p2)
{
    int p1_We=((Ele *)p1)->We,p1_Iq=((Ele *)p1)->Iq;
    int p2_We=((Ele *)p2)->We,p2_Iq=((Ele *)p2)->Iq;
    if(p1_We>p2_We) return 1;
    else if(p1_We<p2_We) return -1;
    else
    {
        if(p1_Iq>p2_Iq) return -1;
        else return 1;
    }
}
int main()
{
    //freopen("a.txt","r",stdin);
    int x,y,len=0;
    while(scanf("%d %d",&x,&y)!=EOF)
    {
        count[len].We=x;
        count[len].Iq=y;
        count[len].sum=1;
        count[len].next=-1;
        count[len].pos=len+1;
        len++;
    }
    qsort(count,len,sizeof(Ele),cmp);
    for(int i=len-2; i>=0; i--)
    {
        y=x=-1;
        for(int j=len-1; j>i; j--)
            if(count[i].We<count[j].We&&count[i].Iq>count[j].Iq)
            {
                if(x==-1)
                {
                    x=count[j].sum;
                    y=j;
                }
                else if(x<count[j].sum)
                {
                    x=count[j].sum;
                    y=j;
                }
            }
        count[i].sum+=count[y].sum;
        count[i].next=y;
    }
    y=0;
    x=count[0].sum;
    for(int i=1; i<len; i++)
        if(x<count[i].sum)
        {
            x=count[i].sum;
            y=i;
        }
    printf("%d\n",x);
    while(y!=-1)
    {
        printf("%d\n",count[y].pos);
        y=count[y].next;
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值