1056 Mice and Rice (25分)

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
using namespace std;
const int maxn=1010;

struct mice
{
    int weight; //重量
    int r; //排名
}m[maxn];


int main()
{
    freopen("1.txt","r",stdin);
    int np,ng;
    queue<int> q;   //设置队列
    scanf("%d%d",&np,&ng);
    for(int i = 0;i<np;i++)
    {
        scanf("%d",&m[i].weight);
    }
    for(int i = 0;i<np;i++)
    {
        int temp;
        scanf("%d",&temp);
        q.push(temp);  //记录老鼠的标号
    }

    int t = np; //记录np

    while(q.size() != 1) //只要还没有决出第一名就继续
    {
        int group = 0;
        if(np % ng == 0) group = np / ng;
        else group = np / ng + 1;  //多出来的组成一组
        for(int i = 0;i<group;i++)
        {
            int k = q.front(); //k记录最大的老鼠的编号
            for(int j = 0;j<ng;j++) //组内对比
            {
                if(j + 1 + i * ng > np) break; //如果最后一组编号超过了np则退出
                int f = q.front();
                m[f].r = group + 1; //给所有老鼠排名,晋级的下一轮会更新
                if(m[k].weight < m[f].weight)
                    k = f;
                q.pop();
            }
            q.push(k); //最大的晋级下一轮
        }
        np = group;
    }

    m[q.front()].r = 1;
    for(int i = 0;i<t;i++)
    {
        printf("%d",m[i].r);
        if(i!=t - 1)
            printf(" ");
    }



    return 0;
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值