Title Link: BZOJ-1874
Problem analysis
This is a combo game that is the and of many individual SG games.
That is, the total game is a combination of a number of single SG games, each SG game (that is, each heap of stones) between each other, each time from a single game to choose a decision, if all the individual game can not make a decision, the game failed.
There is a conclusion that SG (A + B + C ...) = SG (a) ^SG (B) ^SG (c) ...
This problem is not more than 1000 stones per heap, so can be [0, 1000] of the SG value of violence, using the definition of the most primitive SG function, sg (u) = MEX (SG (v)) E (U-V).
The SG value of each pile is then different or up. If you win, just enumerate all the initial scenarios in order and find the winning output and exit.
Code
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include < Algorithm> #include <cmath>using namespace Std;const int maxnum = + 5, MAXN = ten + 5;int N, M, mark_index;int A[MAXN], B[MAXN], Sg[maxnum], mark[maxnum];void calc_sg () {sg[0] = 0; Mark_index = 0;memset (mark, 0, sizeof), for (int i = 1; I <=, ++i) {++mark_index;for (int j = 1; j <= m; + +J) {if (B[j] > i) continue; MARK[SG[I-B[J]] = mark_index;} for (int j = 0; J <=, ++j) {if (mark[j]! = Mark_index) {Sg[i] = J; break;}}}} int main () {scanf ("%d", &n), for (int i = 1; I <= n; ++i) scanf ("%d", &a[i]), scanf ("%d", &m), and for (int i = 1; I <= m; ++i) scanf ("%d", &b[i]); CALC_SG (); int temp = 0;for (int i = 1; I <= n; ++i) temp ^= sg[a[i]];if (temp = = 0) printf ("no\n"); else {printf ("yes\n" ); bool Flag = false;for (int i = 1; I <= n; ++i) {for (int j = 1; j <= m; ++j) {if (B[j] > A[i]) continue;if ((Te MP ^ Sg[a[i]] ^ sg[a[i]-B[J]]) = = 0) {Flag = true;printf ("%d%d\n", I, b[j]); if (Flag) break;}} return 0;}
[Bzoj 1874] [BeiJing2009 Wintercamp] Take the stone game "game theory | SG function "