Matter:
1.很难受,这个想了好长时间,发现没读懂题目。second line 是每个老鼠的质量(Wi is the weight of the i-th mouse),third line 是初始化的排序顺序(initial playing order)。光这个匹配就想了半天。
2.本轮的获胜的排名正好是组数。
3.最后第一名的那个需要最后修改一下,因为最后一组没有修改,所以统一写成1。
Code:
#include<iostream>
#include<queue>
using namespace std;
struct mice{
int pos;
int weight;
}Mice[1005];
int main(){
int np , ng , order;
//input
scanf("%d %d" , &np , &ng);
for(int i = 0 ; i < np ; i ++){
scanf("%d" , &Mice[i].weight);
}
//list queue
queue<int> q;
for(int i = 0 ; i < np ; i ++){
int a;
scanf("%d" , &a);
q.push(a);
}
int q_size = np , group;
while(q.size() != 1){ //until winner approach
//confirm the group
if(q_size % ng == 0) group = q_size / ng;
else group = q_size / ng + 1;
//find the heavest mouse in a group
for(int i = 0 ; i < group ; i ++){
int t = q.front();
for(int j = 0 ; j < ng ; j ++){
if(i * ng + j >= q_size) break;
int f = q.front();
if(Mice[t].weight < Mice[f].weight){
t = f;
}
Mice[f].pos = group + 1;
q.pop();
}
q.push(t);
}
q_size = group;
}
//when queue have only one mouse , put it pos to No.1
Mice[q.front()].pos = 1;
//output
for(int i = 0 ; i < np ; i ++){
if(i == np - 1)
printf("%d" , Mice[i].pos);
else
printf("%d " , Mice[i].pos);
}
return 0;
}