Consider two simple cases first:
- If the initiator can finish the coin once, that is K >= N, then the initiator wins
- If you can only take one coin at a time, that is, k = 1, then if there is an odd number of coins to win, if there is an even number of coins to win.
The rest of the situation is that the initiator can not finish it once, and each time you may take one or two coins.
The rest of the coin will become a chain, if the hand can finish the best, can not be finished, take one or two coins so that the chain into two equal length.
It must be able to do that.
Because if the chain has an odd number of coins, then take the middle one;
If you have an even number of coins, take the middle two.
After becoming equal to the two strands, the initiator takes the number of coins in which chain, and the other one in the other chain, until all the coins are taken.
So the flip-win.
1#include <cstdio>2 3 intMain ()4 {5 //freopen ("In.txt", "R", stdin);6 7 intT scanf"%d", &T);8 for(intKase =1; Kase <= T; kase++)9 {Ten intN, K; Onescanf"%d%d", &n, &k); Aprintf"Case %d:", Kase); - BOOLFirst ; - if(k = =1) First = N &1?true:false; the Else if(k >= n) First =true; - ElseFirst =false; -printf"%s\n", first?" First":"Second"); - } + - return 0; +}
code June
HDU 3951 (game) Coin game