First, the Bashbor game:
There are only a bunch of n items, two people take the things in turn, the rule is to take at least one at a time, the maximum number of M, the last to win the light.
Conclusion:
See Code
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <cstring>5 #defineFRE () freopen ("In.txt", "R", stdin)6 7 using namespacestd;8 intn,m;9 Ten intMain () One { A while(~SCANF ("%d%d",&n,&m)) - { - if(n% (m+1) ==0) theprintf"The initiator loses \ n"); - Else -printf"The initiator wins ."); - } + return 0; -}
Second, Witzov game:
There are two piles of various items, the two take turns from one of the piles to fetch at least one item, at most, or from the two stacks simultaneously take the same item, rules the final winner wins.
Conclusion:
The quantity of the two items is a, b, then k = ABS (b-a), t = min (A, b), Calculate temp = (sqrt (5.0) +1)/2.0, if k * temp = t, then the initiator loses, conversely the initiator wins.
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <cstring>5 #defineFRE () freopen ("In.txt", "R", stdin)6 7 using namespacestd;8 Const intMAXN =1e4;9 intb;Ten One intMain () A { - //FRE (); - Doubletemp = (sqrt (5.0) +1) /2.0; the while(~SCANF ("%d%d",&a,&b)) - { - if(A >b) Swap (A, b); - intK = B-A; + if(A = = (int) (K*temp))//Note Conversions for data types -printf"0\n"); + Else Aprintf"1\n"); at } - return 0; -}
Third, Nimbo:
There are any heap items, the number of items per heap is arbitrary, the two sides take turns to pick up items, each time can only from a pile of items to take part or all of the items, at least one, take the last item to win the person.
Conclusion:
The number of items in the heap is continuously different or (^ operation), if the result is 0, the initiator loses, not 0 o'clock, the initiator wins.
Example: HDU2176
When the sequence of successive XOR values is K (k! = 0), it is assumed that one of the elements a, when a > a ^ k, change A to a^k, you can make the sequence of the XOR value into 0.
1#include <iostream>2#include <cstring>3#include <algorithm>4#include <cstdio>5#include <cmath>6#include <Set>7 #defineINF 0x3f3f3f3f8 9 using namespacestd;TentypedefLong Longll; One Const intMAXN =200000; A intBUF[MAXN]; - - the intMain () - { - intN; - while(SCANF ("%d", &n) &&N) + { - inttemp =0, mmin =INF; + for(inti =0; I < n; i++) A { atscanf"%d",&buf[i]); -Mmin =min (mmin, buf[i]); -Temp ^=Buf[i]; - } - if(temp = =0) -printf"no\n"); in Else - { toprintf"yes\n"); + for(inti =0; I < n; i++) - { the if(Buf[i] > (buf[i]^temp)) *printf"%d%d\n", buf[i],buf[i]^temp); $ }Panax Notoginseng } - } the return 0; +}
Four, Fibonacci game:
There is a pile of items, two people take turns to fetch items, the initiator at least one, at most, no limit, but not to take out the items, after each fetch of the number of items can not exceed the last twice times the number of items taken and at least one piece, take the last item to win the person.
Conclusion :
The initiator wins when and only if the number of these items is not the number in the Fibonacci sequence. (This type of problem can be solved by table)
Example HDU-2516
1#include <iostream>2#include <cstring>3#include <algorithm>4#include <cstdio>5#include <cmath>6#include <Set>7 #defineINF 0x3f3f3f3f8 9 using namespacestd;TentypedefLong Longll; One Const intMAXN =100000; A - ll BUF[MAXN]; - Set<ll>s; the voidInit () - { -buf[0] = buf[1] =1; - for(inti =2; i < MAXN; i++) + { -Buf[i] = buf[i-1] + buf[i-2]; + S.insert (Buf[i]); A } at } - - - intMain () - { - ll X; in init (); - while(SCANF ("%lld", &x) &&x) to { + if(S.count (x)) -printf"Second win\n"); the Else *printf"First win\n"); $ }Panax Notoginseng return 0; -}
Game Conclusion Record