#include <iostream>
#include <queue>
using namespace std;
struct mouse {
int weight;
int rank;
} mice[1005];
queue<int> game;
int main() {
int NP, NG;
cin >> NP >> NG;
for (int i = 0; i < NP; i++) {
cin >> mice[i].weight;
}
int order, count = 0, group;
for (int i = 0; i < NP; i++) {
cin >> order;
count++;
game.push(order);
}
if (count % NG == 0)
group = count / NG;
else
group = count / NG + 1;
int temp = NP;
while (game.size() != 1) {
for (int i = 0; i < group; i++) {
int greatest = game.front();
//game.pop();
for (int j = 0; j < NG; j++) {
if (i * NG + j >= temp)
break;
if (mice[game.front()].weight > mice[greatest].weight) {
greatest = game.front();
}
mice[game.front()].rank = group + 1;
game.pop();
}
game.push(greatest);
}
temp = group;
if (group % NG == 0)
group /= NG;
else
group = group / NG + 1;
}
mice[game.front()].rank = 1;
for (int i = 0; i < NP; i++) {
if (i < NP - 1)
cout << mice[i].rank << " ";
else
cout << mice[i].rank << "\n";
}
return 0;
}
通过控制比赛组数,调整出队入队来实现对比赛的模拟。