#include<stdio.h>
#include<queue>
using namespace std;
const int maxn = 1000 + 10;
struct mouse{
int weight;//老鼠的重量
int Rank;//老鼠的排名
}a[maxn];
int main()
{
queue<int> q;
int np, ng, order, group;
scanf("%d%d", &np, &ng);
for(int i = 0; i < np; i ++)
{
scanf("%d", &a[i].weight);
}
for(int i = 0; i < np; i ++)
{
scanf("%d", &order);
q.push(order);
}
int temp = np;//记录每一轮的老鼠数量
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(a[front].weight > a[k].weight)
{
k = front;
}
a[front].Rank = group + 1;
q.pop();
}
q.push(k);//让重量最大的老鼠晋级
}
temp = group;
}
a[q.front()].Rank = 1;
for(int i = 0; i < np; i ++)
{
printf("%d", a[i].Rank);
if(i < np - 1)
printf(" ");
}
return 0;
}
直接看英文题目,我连样例都没推出来,呜呜呜,太菜了!