You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
554 B
25 lines
554 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
int n;
|
|
queue<int> q;
|
|
int cnt; //当前轮次第几个
|
|
|
|
int main() {
|
|
cin >> n;
|
|
//为啥这里把所有人员都入队列呢?当面要解释清楚
|
|
for (int i = 1; i <= n; i++) q.push(i);
|
|
//如果还剩余大于1个
|
|
while (q.size() > 1) {
|
|
//取出一个
|
|
int t = q.front();
|
|
q.pop();
|
|
cnt++;//点了一个数
|
|
|
|
if (cnt == 3) cnt = 0;
|
|
else q.push(t);
|
|
}
|
|
//输出最后一个
|
|
cout << q.front();
|
|
return 0;
|
|
} |