vector 解决约瑟夫环问题
总共 n个人 从s号开始,m个删去一个
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int>v;
int n, s, m;
cin >> n >> s >> m;
for (int i = 1; i <= n; i++)
{
v.push_back(i);
}
auto it = v.begin() + s-1;
while(v.size()-1)
{
for (int j = 0; j < m-1; j++)
{
it++;
if (it == v.end())
it = v.begin();
}
cout << *it << " ";
it = v.erase(it);
if (it == v.end())
it = v.begin();
}
}