public class DiuS {
int rens,jies,qis;
int per[];
int flag = 0;
public DiuS(int rens,int jies,int qis){
this.rens=rens;
this.jies=jies;
this.qis=qis;
int b=jies-1;
int i=qis-1;
per=new int[rens];
for(int m=0;m<per.length;m++){
per[m]=-1;
}
while(!(yanZ(per))){
for(int j=b;j>=0;j--){
while(per[i]==0){
i++;
if(i==rens){
say();
i=0;
}
}
per[i]=j;
i++;
if(i==rens){
say();
i=0;
}
}
}
say();
}
public boolean yanZ(int[] aa){
int result=0;
for(int i=0;i<aa.length;i++){
if(aa[i]!=0){
result++;
this.flag=i;
}
}
if(result==1){
return true;
}
else{
return false;
}
}
public void say(){
for(int pe:per){
System.out.print(pe+" ");
}
System.out.println();
}
public static void main(String[] args) {
DiuS dddd=new DiuS(20,9,1);
System.out.println(dddd.rens+"个孩子 第"+dddd.qis+"个孩子开始"+"数到"+dddd.jies+"离开");
System.out.println("第"+(dddd.flag+1)+"个孩子获胜");
}
}