//todo 段错误 天勤 1056 Mice and Rice P262下

//todo 段错误  天勤 1056 Mice and Rice P262下
#include <iostream>
#include <queue>
using namespace std;
struct mouse{
    int weight;
    int r;
};
int main(){
    int NP,NG,order;
    mouse mouses[1010];
    cin>>NP>>NG;
    for(int i=0;i<NP;i++){
        cin>>mouses[i].weight;
    }
    queue<int> q;
    for(int i=0;i<NP;i++){
        cin>>order;
        q.push(order);
    }
    int temp = NP,group;
    while(q.size() != 1){
        if(temp % NG ==0) group = temp/NG;
        else group = temp/NG +1;
        for(int i=0;i<group;i++){
            int k = q.front();
            for(int j=0;j<NG;++j){
                if(i*NG + j > temp) break;
                int front = q.front();
                if(mouses[front].weight > mouses[k].weight) k =front;
                mouses[front].r = group +1;
                q.pop();
            }
            q.push(k);
        }
        temp = group;
    }
    mouses[q.front()].r = 1;
    for(int i=0;i<NP;i++){
        cout<<mouses[i].r;
        if(i<NP-1) cout<<" ";
    }

    return 0;
}

全部评论

相关推荐

未知的命运:大佬这都找不到我还找啥啊
点赞 评论 收藏
分享
10-10 01:10
已编辑
深圳大学 测试开发
面了100年面试不知...:六月到九月,四个项目一个实习,是魔丸吗
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务