package d;
import java.util.LinkedList;
import java.util.List;
public class test {
public static void main(String[] args) {
int num = 4;
List<Integer> all = new LinkedList<Integer>();
for(int i = 1;i <= num;i++){
all.add(i);
}
System.out.println(all);
int i = 0;
int s =all.size();
//System.out.println(all[0]);
for(int n = 1;n < num ;n++){
i = (i + 2) % all.size();
all.remove(i);
}
System.out.println("最后剩下的是第 " + all.get(0) + " 个人");
}
}
约瑟夫环算法java
最新推荐文章于 2024-08-02 17:09:09 发布