比赛 板子大赛 评测结果 AAAAA
题目名称 约瑟夫问题 最终得分 100
用户昵称 喵喵喵 运行时间 0.019 s
代码语言 C++ 内存使用 3.33 MiB
提交时间 2025-01-22 09:48:58
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
queue<int> q;
int main()
{
	freopen("ysf.in","r",stdin);
	freopen("ysf.out","w",stdout);
	int n,k;
	cin >> n >> k;
	for(int i = 1; i <= n; ++i)
	{
		q.push(i);
	}
	int cnt = 0;
	while(!q.empty())
	{
		cnt++;
		if(cnt == k)
		{
			cout << q.front() << endl;
			q.pop();
			cnt = 0;
		}
		else
		{
			int x = q.front();
			q.pop();
			q.push(x);
		}
	}
}