1056 Mice and Rice (25分)
Mice and Rice is the name of a programming contest in which each programmer must write a piece of code to control the movements of a mouse in a given map. The goal of each mouse is to eat as much rice as possible in order to become a FatMouse.
First the playing order is randomly decided for NP programmers. Then every NG programmers are grouped in a match. The fattest mouse in a group wins and enters the next turn. All the losers in this turn are ranked the same. Every NG winners are then grouped in the next match until a final winner is determined.
For the sake of simplicity, assume that the weight of each mouse is fixed once the programmer submits his/her code. Given the weights of all the mice and the initial playing order, you are supposed to output the ranks for the programmers.
题目大意:就是说有np只老鼠,每ng只mouse分为一组,每组选出最重的那只,晋级下一轮,直到最终的winner产生
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstring>
#include<queue>
#define maxn 1010
using namespace std;
struct node{
int weight;
int rank;
}pre[maxn];
queue<int> qu;
int main(){
int np,ng,order; //11个num,3个一组
scanf("%d%d",&np,&ng);
for(int i=0;i<np;i++){
scanf("%d",&pre[i].weight);
}
for(int i=0;i<np;i++){
scanf("%d",&order);
qu.push(order);
}
int num=np,group; //num正在比赛的人数, group组数
while(qu.size()!=1){
if(num%ng==0) group=num/ng;
else group=num/ng+1;
for(int i=0;i<group;i++){ //每次一组
int k=qu.front();
for(int j=0;j<ng;j++){ //每组的max
if(i*ng+j>=num) break; //针对最后一组
int first=qu.front();
if(pre[k].weight<pre[first].weight){
k=first;
}
pre[first].rank=group+1; //前面选出了group个mouse,所以这些mice的排名就是group+1
qu.pop();
}
qu.push(k);//晋级
}//一轮结束
num=group;
}
pre[qu.front()].rank=1;
for(int i=0;i<np;i++){
printf("%d",pre[i].rank);
if(i<np-1) printf(" ");
}
return 0;
}