Hdu 5088 Revenge of Nim II (Gaussian Deyuan)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.