题解:P1996 约瑟夫问题
简单模拟题。
题意
有一个有
思路
其实只需要用一个循环队列模拟就行了,每一次循环
Code
用 STL 的队列模拟的。
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
queue<int>q;
for(int i=1;i<=n;i++)q.push(i);
while(!q.empty()){
for(int i=1;i<k;i++){
q.push(q.front());
q.pop();
}
cout<<q.front()<<' ';
q.pop();
}
return 0;
}