竞赛
考级
#include<bits/stdc++.h> using namespace std; int main(){ queue<int>q; int n,m,cnt=0; cin>>n>>m; for(int i=1;i<=n;i++){ q.push(i); } while(!q.empty()){ cnt++; if(cnt==m){ cout<<q.front()<<" "; cnt=0; }else{ q.push(q.front()); } q.pop(); } return 0; }
暗區突圍随风0351
#include<iostream> #include<queue> using namespace std; int cnt; int main(){ queue<int>a; int n,m; cin>>n>>m; for(int i=1;i<=n;i++){ a.push(i); } while(!a.empty()){ cnt++; if(cnt==m){ cout<<a.front()<<" "; cnt=0; }else{ a.push(a.front()); } a.pop(); } return 0; }
TimeLimitExceed
#include<iostream> #include<queue> using namespace std; int cnt; int main(){ queue<int>a; int n,m; cin>>n>>m; for(int i=0;i<n;i++){ a.push(i); } while(!a.empty()){ cnt++; if(cnt==m){ cout<<a.front()<<" "; }else{ a.push(a.front()); } a.pop(); } return 0; }