题目:P1996 约瑟夫问题 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,count=0,x=0;
cin>>n>>m;
queue<int>q;
for(int i=1;i<=n;i++)
{
q.push(i);
}
while(!q.empty())
{
count++;
x=q.front();
q.pop();
if(count==m)
{
cout<<x<<" ";
count=0;
}
else
q.push(x);
}
return 0;
}