大佬们这个应该怎么改,求助

P1996 约瑟夫问题

``` #include<iostream> using namespace std; bool a[1000]; int n,m,t,s,f; int main(){ cin>>n>>m; for(t=0;t<n;t++) a[t]=false; t=0; s=0; f=0; do{ ++t; if(t==n+1) t=1; if(a[t]==false) ++s; if(s==m){ s=0; cout<<t<<" "; a[t]=true; ++f; } }while(f!=n); return 0; } ``` **建议重写(我老师说的)**
by Ethan216 @ 2023-08-15 16:21:17


建议重写
by 13579L @ 2023-08-15 16:22:47


队列的代码如下(洛谷重视学术诚信!!!) ``` #include<iostream> #include<queue> using namespace std; int n,m; int main(){ cin>>n>>m; queue<int> q; for(int i=1;i<=n;i++) q.push(i); while(q.size()){ for(int i=0;i<m-1;i++){ q.push(q.front()); q.pop(); } cout<<q.front()<<" "; q.pop(); } return 0; } ```
by Ethan216 @ 2023-08-15 16:31:12


```cpp #include <iostream> #include <queue> using namespace std; queue<int> q; int main(){ int n, k; cin >> n >> k; for (int i = 1; i <= n; i ++){ q.push(i); } while (!q.empty()){ for (int i = 0; i < k - 1; i ++){ q.push(q.front()); q.pop(); } cout << q.front() << " "; q.pop(); } return 0; } ``````
by garyzhao @ 2023-08-15 16:31:31


@[garyzhao](/user/923369) 咱俩一块学的
by Ethan216 @ 2023-08-15 16:32:50


|