一道博弈题,可以先用SG函数打表,看看什么时候先手会输。
发现(1,2),(3,5),(4,7)...其实就是个威佐夫博弈。
实际上向左边移动等价于取第一堆石子,向下移动等价于取第二堆石子,向左下移动等价于两堆同时取
相同数目的石子。
#include <stdio.h> #include <utility> #include <vector> #include <string.h> #include <math.h> #include <iostream> #include <stdlib.h> #include <time.h> #include <math.h> #include <queue> 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 = 2e4 + 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 dir[3][2] = { -1, -1, -1, 0, 0, -1 }; int d[1010][1010]; void dfs(int x, int y) { if (d[x][y] != -1) return ; int flag = 1; for (int i = 0; i < 3; i++) { int flag = 1; int nx = x, ny = y; nx += dir[i][0], ny += dir[i][1]; while (nx >= 0 && nx <= 100 && ny >= 0 && ny <= 100) { dfs(nx, ny), flag &= d[nx][ny]; nx += dir[i][0], ny += dir[i][1]; } if (!flag) { d[x][y] = 1; return; } } d[x][y] = 0; return; } int main() { #ifdef LOCAL freopen("E:/input.txt", "r", stdin); #endif /* memset(d, -1, sizeof d); d[1][0] = d[0][1] = d[1][1] = 1; d[0][0] = 0; for (int i = 0; i <= 100; i++) for (int j = 0; j <= 100; j++) dfs(i, j); for (int i = 0; i <= 20; i++) for (int j = 0; j <= 20; j++) if (d[i][j] == 0) cout << i << " " << j << " " << "Lao Wang" << endl; */ int a, b; double r = (sqrt(5) + 1) / 2; while (~scanf("%d%d", &a, &b)) { if (a > b) swap(a, b); int result = (b - a) * r; if (result == a) puts("Lao Wang"); else puts("Xiao Ren"); } return TIME; }