比赛 | 板子大赛 | 评测结果 | AAAAA |
---|---|---|---|
题目名称 | 约瑟夫问题 | 最终得分 | 100 |
用户昵称 | 李金泽 | 运行时间 | 0.014 s |
代码语言 | C++ | 内存使用 | 3.01 MiB |
提交时间 | 2025-01-22 11:08:27 | ||
#include<cstdio> #include<queue> using namespace std; int n,k; queue<int>q; int main() { freopen("ysf.in","r",stdin);freopen("ysf.out","w",stdout); scanf("%d%d",&n,&k); for(int i=1;i<=n;i++)q.push(i); while(n) { int x=(k-1)%n+1; while(--x)q.push(q.front()),q.pop(); n--;printf("%d\n",q.front());q.pop(); } return 0; }