解题思路: vector添加和删减元素 形成循环队列
注意事项:
参考代码:
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int n;
cin>>n;
vector<int> people;
for(int i=0;i<n;i++)
people.push_back(i);
int k=1;
while(people.size()>1)
{
if (k!=3)
{
people.push_back(people[0]);
people.erase(people.begin());
k+=1;
}
else
{
people.erase(people.begin());
k = 1;
}
}
cout<<people[0]+1;
return 0;
}
0.0分
0 人评分