This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include<iostream>
using namespace std;
const int N = 610;
int a[N];
int main() {
//n:总人数,s:本轮已计数人数,p:现在检查的是第几个人
int n, s = 0, p = 0;
cin >> n;
//一共需要出圈次数n-1次,最终需要剩下一个人
for (int i = 1; i <= n - 1; i++) {
//如果本轮没有达到三个人点数的情况下,就一直在想办法找三个人
while (s < 3) {
if (p == n)p = 0; //如果走到了最后一个,需要把p的位置调整为虚拟的0号位置,这个是难点,不好想
p++; //不管是不是有效的数字,是不是出过列,我就是要往前一直走,我就是个指针,我的作用是当找到第3个人的时候,这个人的下村是多少。
if (a[p] == 0) s++; //只有标识为0的才能查数,是1的表示已经出列,不能查数
}
//找到数3的了
a[p] = 1; //把这个位置标识为已经出列了
s = 0; //本轮S的任务完成,清零,让下次查数有个好的计数器
for (int i = 1; i <= n; i++) if (a[i] == 0)cout << i;//输出没有出列的人
return 0;