PTA_A_1056

#include <iostream>
#include <queue>
#define N 1000+10
using namespace std;

int main()
{
    int np, ng;
    cin >> np >> ng;
    int W[N];
    int ans[N];
    queue<int> Order;
    for (int i = 0; i < np; i++)
        cin >> W[i];
    for (int i = 0; i < np; i++) {
        int a;
        cin >> a;
        Order.push(a);
    }
    int num = 0;
    int rnum = np;
    int  rank = (rnum / ng) + (rnum % ng == 0 ? 0 : 1) + 1;
    while (!Order.empty()) {
        int count = ng;
        int maxw;
        while (count-- && num < rnum) {
            if (count == ng - 1) maxw = Order.front();
            if (W[maxw] < W[Order.front()])
                maxw = Order.front();
            ans[Order.front()] = rank;
            Order.pop();
            num++;
        }
        Order.push(maxw);
        if (num==rnum) {
            num = 0;
            rnum = (rnum / ng) + (rnum % ng == 0 ? 0 : 1);
            rank = (rnum / ng) + (rnum % ng == 0 ? 0 : 1)+1;
        }
               
        if (Order.size() == 1) {
            ans[Order.front()] = 1;
            Order.pop();
        }
    }
    for (int i = 0; i < np; i++) {
        if (i == 0)
            cout << ans[i];
        else
            cout << " " << ans[i];
    }
   
    return 0;
}


发布了195 篇原创文章 · 获赞 9 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/zero_1778393206/article/details/104151008
PTA