约瑟夫是一个无聊的人!!!
n个人(n<=100)围成一圈,从第一个人开始报数,数到m的人出列,再由下一个人重新从1开始报数,数到m的人再出圈,……依次类推,直到所有的人都出圈,请输出依次出圈人的编号.
n m
出圈的编号
10 3
3 6 9 2 7 1 8 5 10 4
m, n \le 100m,n≤100
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<queue> using namespace std; queue<int>q; int n,m; 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; }
原文:https://www.cnblogs.com/xiongchongwen/p/11824832.html