求助

P1996 约瑟夫问题

用队列更好写吧 ```cpp #include<bits/stdc++.h> using namespace std; typedef long long ll; int n,m; queue <int> q; int main() { scanf("%d%d",&n,&m); 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(); } printf("%d ",q.front()); q.pop(); } return 0; } ```
by little_sheepl @ 2024-01-22 13:51:34


|