import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
/**
* 丢手绢问题
* 使用链表
* @author qh
*
*/
public class Jzf {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println(genIt(50,3));
}
/**
* 处理方法
* @param total
* @param n
* @return
*/
public static int genIt(int total,int n){
List<Integer> dataList=new LinkedList<Integer>();
//赋值
for(int i=0;i<total;i++){
dataList.add(new Integer(i+1));
}
int index=-1;//假设已经移除一个了
//取余数
while(dataList.size()>1){
index=(index+n)%dataList.size();
dataList.remove(index--);
}
return dataList.get(0);
}
}
import java.util.List;
import java.util.Scanner;
/**
* 丢手绢问题
* 使用链表
* @author qh
*
*/
public class Jzf {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println(genIt(50,3));
}
/**
* 处理方法
* @param total
* @param n
* @return
*/
public static int genIt(int total,int n){
List<Integer> dataList=new LinkedList<Integer>();
//赋值
for(int i=0;i<total;i++){
dataList.add(new Integer(i+1));
}
int index=-1;//假设已经移除一个了
//取余数
while(dataList.size()>1){
index=(index+n)%dataList.size();
dataList.remove(index--);
}
return dataList.get(0);
}
}