Ba Shi game:
A person to take 1~m, then who face m+1 situation of the time will be defeated. Suppose n=k* (m+1) +s, (k for any, s<m+1), then I (the initiator) First Take that s, and then let another person take, from now on, as long as I take the number with the number of the previous person and equal to m+1, so after the inevitable face will be defeated situation, That is, when the last one is finished, it must be T (t<m) to me, that is, I win. such as 2,23= (3x7) +2; that I first took off 2, and no matter how much I can make this round a total of 3, and then he will face 3 this situation, and then I will win, then when will be defeated, it is obvious if I face is (m+1) multiples of the situation will be defeated. That is, we only need to determine whether n% (m+1) equals 0 to know who wins who is negative.
1#include <cstdio>2 intMain ()3 {4 intt, N, M;5scanf"%d", &t);6 while(t--){7scanf"%d%d", &n, &m);8 if(N <=m)9printf"first\n");Ten Else if(n% (M +1) ==0) Oneprintf"second\n"); A Else -printf"first\n"); - } the return 0; -}
HDU1846 Bashbor Game