#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn=1010;
struct mouse {
int weight, order, rank;
}mouse[1010];
queue<int> q;
int main() {
int np, ng,turn[maxn];
cin >> np >> ng;
int weight, order;
for (int i = 0;i < np;i++) {
cin >> weight;
mouse[i].weight = weight;
}
for (int i = 0;i < np;i++) {
cin >> order;
q.push(order);
}
int temp = np;
int group;
while (q.size() != 1) {
if (temp%ng != 0) { group = temp / ng + 1;
}
else {
group = temp / ng;
}
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 (mouse[front].weight > mouse[k].weight) {
k = front;
}
mouse[front].rank = group + 1;
q.pop();
}
q.push(k);
}
temp = group;
}
mouse[q.front()].rank = 1;
for (int i = 0;i < np;i++) {
printf("%d ", mouse[i].rank);
if (i < np - 1)printf(" ");
}
system("pause");
return 0;
}
PAT #A1051 Pop Sequence
最新推荐文章于 2022-08-27 21:48:53 发布