/**
* 约瑟夫环 公式法
*/
public static int Joseph_Ring(int n ,int m){
int p = 0;
for (int i = 2;i<=n;i++){
p=(p+m)%i;
}
return p+1;
}
参考:https://blog.csdn.net/u011500062/article/details/72855826
按逻辑写
public static int Joseph_Ring2(List list , int m){
int p = 0,numer=1;
while(list.size()>1){
if (numer%m==0) {
list.remove§;
p–;
}
p++;
numer++;
if(p>list.size()-1){
p=0;
}
}
return list.get(0);
}