捡石头

捡石头

https://ac.nowcoder.com/acm/problem/14388

经典Bash博弈。
结论:n % (m + 1) = 0时先手必输,否则后手必赢。
当n % (m + 1) = 0时,先手如果出k,后手跟着出一个(m + 1 - k)即可。
最终会进行(n / (m + 1)) * 2轮,后手胜。
当n % (m + 1) != 0可知n % (m + 1) <= m, 所以先手先取出n % (m + 1)。
则剩余的石子个数满足n % (m + 1) = 0,轮到后手了这时候后手是必败状态,即先手获胜。

#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

#ifdef LOCAL
#define debug(x) cout << "[" __FUNCTION__ ": " #x " = " << (x) << "]\n"
#define TIME cout << "RuningTime: " << clock() << "ms\n", 0
#else
#define TIME 0
#endif
#define hash_ 1000000009
#define Continue(x) { x; continue; }
#define Break(x) { x; break; }
const int mod = 998244353;
const int N = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
#define gc p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;
inline int read(){ static char buf[1000000], *p1 = buf, *p2 = buf; register int x = false; register char ch = gc; register bool sgn = false; while (ch != '-' && (ch < '0' || ch > '9')) ch = gc; if (ch == '-') sgn = true, ch = gc; while (ch >= '0'&& ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gc; return sgn ? -x : x; }
ll fpow(ll a, int b, int mod) { ll res = 1; for (; b > 0; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; }

int main()
{
#ifdef LOCAL
    freopen("E:/input.txt", "r", stdin);
#endif
    int n, m;
    cin >> n >> m;
    printf("%s\n", n % (m + 1) == 0 ? "second" : "first");
    return TIME;
}
全部评论

相关推荐

斑驳不同:还为啥暴躁 假的不骂你骂谁啊
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务