public static void main(String args[]){
int n =5;
int m=0;
int leftCount=5;
boolean b[] = new boolean[leftCount];
int count=0;
while(leftCount>1){
if(b[m]==false){
++count;
if(count ==3){
b[m] = true;
--leftCount;
count = 0;
}
}
++m;
if(m == n){
m =0;
}
}
for(boolean arr:b){
System.out.println(arr);
}
}
n个人围成一圈,数1 2 3,数到3的退出,最后一个人是原来的第几号。
int n =5;
int m=0;
int leftCount=5;
boolean b[] = new boolean[leftCount];
int count=0;
while(leftCount>1){
if(b[m]==false){
++count;
if(count ==3){
b[m] = true;
--leftCount;
count = 0;
}
}
++m;
if(m == n){
m =0;
}
}
for(boolean arr:b){
System.out.println(arr);
}
}
n个人围成一圈,数1 2 3,数到3的退出,最后一个人是原来的第几号。

被折叠的 条评论
为什么被折叠?



