csppass
连续 00 XP登录 / 注册
202134完善程序枚举与模拟普及-

Josephus问题:①处应填

题目

完善程序:有 n个人围成一个圈,依次标号0至n-1。从0号开始,依次0,1,0,1,…交替报数,报到1的人离开,直至圈中只剩下一个人。求最后剩下人的编号。 #include <iostream> using 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; } ①处应填( )

考点拆解
算法思想与复杂度
易错提醒
阅读程序题要按变量变化顺序手推,不要跳步
选择题要检查单位、边界和题目中的否定词