2021 年第 38 题完善程序枚举与模拟普及-
Josephus问题:⑤处应填
题目
完善程序:Josephus问题(接上题)。 #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; } ⑤处应填( )
考点拆解
算法思想与复杂度
易错提醒
阅读程序题要按变量变化顺序手推,不要跳步
选择题要检查单位、边界和题目中的否定词