完善程序(1)
1-5题 组合体
(Josephus 问题)有 n个人围成一个圈,依次标号 0 至n-1。从 0 号开始,依次 0, 1, 0, 1, … 交替报数,报到 1 的人会离开,直至圈中只剩下一个人。求最后剩下人的编号。
试补全模拟程序。
#includeusing namespace std; const int MAXN = 1000000; int F[MAXN]; int main() { int n; cin >> n; int i = 0, p = 0, c = 0; while (①) { if (F[i] == 0) { if (②) { F[i] = 1; ③; } ④; } ⑤; } int ans = -1; for (i = 0; i < n; i++) if (F[i] == 0) ans = i; cout << ans << endl; return 0; }
①处应填( )
i < n
c < n
i < n - 1
c < n - 1