题目
去官网看
思路
主要是通过队列来对问题进行模拟,每次抛出一个小朋友,判断此时计数是否满足淘汰的条件,若不满足则把小朋友重新加到队列末尾,直到队列中还剩下一个小朋友则游戏结束。
C++ 代码
#include <iostream>
#include <queue>
using namespace std;
int main()
{
int n, k;
int r = 1, t = 1;
queue<int> q;
cin >> n >> k;
for (int i = 1; i <= n; ++i)
{
q.push(i);
}
while (!q.empty())
{
r = q.front();
q.pop();
if (t%k == 0 || t % 10 == k)
{
;
}
else
{
q.push(r);
}
++t;
}
cout << r << endl;
system("pause");
return 0;
}
参考
https://blog.csdn.net/wl16wzl/article/details/79275069
https://blog.csdn.net/Jason_first/article/details/79111163