(Josephus 问题) 有 n 个人围成一个圈,依次标号 0 至n−1。从 0 号开始,依次 0,1,0,1,… 交替报数,报到 1 的人会离开,直至圈中只剩下一个人。求最后剩下人的编号。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <stdio.h> const int MAXN = 1000000; int F[MAXN]; int main() { int n; scanf("%d", &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; printf("%d", ans); return 0; } |
0 of 5 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 5 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
①处应填( )
②处应填( )
③处应填( )
④处应填( )
⑤处应填( )