#include <bits/stdc++.h>
using namespace std;
const int r = 4e6;
int a[r];
int main(){
int n, m;
cin >> n >> m;
queue<int>q;
for(int i = 1; i <= n; i++)
q.push(i);
while(!q.empty()){
for(int i = 1; i < m; i++){
q.push(q.front());
q.pop();
}
cout << q.front() << " ";
q.pop();
}
cout << endl;
return 0;
}
P1996 约瑟夫问题
于 2024-01-28 18:46:28 首次发布
本文介绍了如何使用C++语言中的queue容器和循环结构实现一个环形队列,通过输入n和m,模拟了队列的操作过程。
摘要由CSDN通过智能技术生成