标签:
/* *约瑟夫环问题 * 抱1 2 3 */ import java.util.*; public class Yuan{ public static void main(String[] args) throws Exception{ Scanner input = new Scanner(System.in); int p = input.nextInt(); System.out.println(leftPerson(p)); } public static int leftPerson(int n) throws Exception { boolean[] per = new boolean[n]; for (int i = 0; i < per.length; i++) { per[i] = true; } int t = 0, len = per.length; while (len > 1) { for (int i = 0; i < per.length; i++) { if (per[i]) { t++; if (t == 3) { t = 0; per[i] = false; len--; } } } } int a = 0; for(int j = 0;j<per.length;j++){ if(per[j]=true){ a = j; } } return a; } }
标签:
原文地址:http://www.cnblogs.com/sumbud/p/4869407.html