publicstaticintnPeople(int n){ int count = n; int p = 0; boolean[] a = newboolean[n]; while (count > 1) { for (int i = 0; i < n; i++) { if (!a[i]) p++; if (p == 3) { a[i] = true; count --; p = 0; } } } int res = 0; for (int i = 0; i < n; i++) { if (!a[i]) res = i + 1; } return res; }
publicstaticintnPeople(int n, int m){ int count = n; int p = 0; boolean[] a = newboolean[n]; while (count > 1) { for (int i = 0; i < n; i++) { if (!a[i]) p++; if (p == m) { a[i] = true; count --; p = 0; } } } int res = 0; for (int i = 0; i < n; i++) { if (!a[i]) res = i + 1; } return res; }