暴力+模拟
#include<iostream> #include<cstring> using namespace std; int ans, k, k2; bool a[30]; bool f(int m){ int u = 0; memset(a, false, sizeof(a)); for (int j = 0; j < k; ++j){ //杀掉k个人 int n = m % (k2 - j); if (k2 - j <= m)n += k2 - j; //将圈子缩小 for (int j = 1; j <= n; ++j){ //模拟走到要杀的人那里 u++; while (a[u] == true)++u; if (u>k2)u = 1; } a[u] = true; if (u <= k) return false; } return ans = m; } int main(){ cin >> k; k2 = k * 2; for (int i = k + 1; !f(i); ++i); cout << ans << endl; return 0; }