题解 | #约瑟夫环#

约瑟夫环

https://ac.nowcoder.com/acm/problem/22227

#include<bits/stdc++.h> using namespace std; int main() { queuep; int n,k,m; cin>>n>>k>>m; for(int i=0;i<n;i++) { p.push(i); } while(p.front()!=k) { int m=p.front(); p.pop(); p.push(m); } int cnt=0; while(p.size()!=1) { cnt++; if(cnt<m) { int x=p.front(); p.pop(); p.push(x); } else{ cnt=0; p.pop(); } } cout<<p.front(); }

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务