Link: hdu 5088 Revenge of Nim II
Nim game deformation, because the game is unfair, so now change the rules, the latter hand can select a number of stones to remove, the remaining stones
To play the game and ask if the latter hand may win.
Solution: in fact, it is to take out non-0 piles of stones, so that the Nim is 0. Because it is Nim and (or), we create an equation with every bit and list 40 square meters.
Process, or form Gaussian elimination, because all 0 must be a solution, so the equation must have a solution, then there is a multi-solution situation that there is a self-owned variable.
# Include <cstdio> # include <cstring> # include <algorithm> using namespace std; const int maxn = 1000; typedef long ll; typedef int Mat [maxn + 5] [maxn + 5]; int gauss (Mat A, int m, int n) {int I = 0, j = 0, k, r, u; while (I <m & j <n) {r = I; for (k = I; k <m; k ++) {if (A [k] [j]) {r = k; break ;}} if (A [r] [j]) {if (r! = I) {for (k = 0; k <= n; k ++) swap (A [r] [k], A [I] [k]);} for (u = I + 1; u <m; u ++) {if (A [u] [j]) for (k = I; k <= n; k ++) A [u] [k] ^ = A [I] [k];} I ++;} j ++;} return n-I ;} int N; Mat a; int main () {int cas; scanf ("% d", & cas); while (cas --) {ll x; scanf ("% d", & N); memset (a, 0, sizeof (a); for (int I = 0; I <N; I ++) {scanf ("% I64d", & x); for (int j = 0; j <45; j ++) a [j] [I] = (x> j) & 1;} int S = gauss (a, 45, N); printf ("% s \ n", ans? "Yes": "No");} return 0 ;}
Hdu 5088 Revenge of Nim II (Gaussian Deyuan)