Topic Ideas:
For the Nim game we know: Op=a[1]^a[2]......a[n], if op==0 will fail
A simple mathematical formula: if Op=a^b then: op^b=a;
The value for heap a[i],op^a[i] represents the value or value of the remaining heap values.
We now want to change a[i] to a smaller value so that op^a[i]=0, in turn, a[i]=op^0, and it's good to output it.
#include <stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<iostream>#include<algorithm>#defineINF 0x3f3f3f3f#defineMAXSIZE 1000005using namespacestd;intA[maxsize];voidGame (intN) { intop=0; for(intI=1; i<=n; i++) op^=A[i]; if(op==0) {printf ("no\n"); return; } Else{printf ("yes\n"); for(intI=1; i<=n; i++) {op=op^A[i]; intk=op^0; if(K <A[i]) {printf ("%d%d\n", a[i],k); } op=op^A[i]; } }}intMain () {intN; while(SCANF ("%d",&N), N) { for(intI=1; i<=n; i++) scanf ("%d",&A[i]); Game (n); } return 0;}View Code
HDU 2176 (M heap) Stone game Nim game