标签:
package com.tfj.algorithm;
import java.util.ArrayList;
import java.util.List;
public class TheLast {
public static void main(String[] args) {
List list = new ArrayList();
for (int i = 1; i <= 100; i++) {
list.add(i);
}
int point = 0, number = 1;
while (list.size() > 1) {
if (number % 3 == 0) {
list.remove(point);
--point;
}
++point;
++number;
if (point > list.size() - 1) {
point = 0;
}
}
System.out.println("最后剩下的数为:" + list.get(0));
}
}
100个小孩排成一圈,从第一个小孩开始1至3报数,凡报为3的小孩从圈中出来,,求最后出圈的小孩的顺序号是多少
标签:
原文地址:http://www.cnblogs.com/tufujie/p/4929937.html