Topic Links:
1020-a Childhood Game
Title Description:
Alice and Bob are playing pinball, the two take the marbles, each time only one or two, when Alice as the initiator who took the last one is the loser, and Bob as the initiator who took the last one is the winner, ask the last who is the winner?
Problem Solving Ideas:
Very basic game topic, we can know when Alice as the initiator: N=1 (Alice lose), N=1 (Alice Win), N=2 (Alice Win), N=4 (Alice lose), N=5 (Alice win).
As can be seen from the above, because each time can take one or two, Alice must make a choice for their own advantage, so there is a[n] =! (A[n-1] && a[n-2]) (1 is win,0 for lose).
For Bob as the initiator is also similar to the above push to method, a[n] =! (A[n-1] && a[n-2]).
1#include <bits/stdc++.h>2 using namespacestd;3 intMain ()4 {5 Long LongN, t, L =0;6 Charstr[Ten];7scanf ("%lld", &t);8 while(T--)9 {Tenscanf ("%lld%s", &n, str); One if(!STRCMP (str,"Bob")) A { - if(n%3==0) -printf ("Case %lld:alice\n", ++l); the Else -printf ("Case %lld:bob\n", ++l); - } - Else + { - if(n%3==1) +printf ("Case %lld:bob\n", ++l); A Else atprintf ("Case %lld:alice\n", ++l); - } - } - return 0; -}
。
Lightoj 1020-a Childhood Game (game)