Ultraviolet A 10561-treblecross
Question Link
A string with 'X' and '. ', which can be in '. 'position X. Whoever releases three 'X' wins first.
Train of Thought: SG function. If each string has an X above it, the four surrounding locations will be the Forbidden Zone (it will be defeated if it is put down ), therefore, we can divide X into several sub-games to find the exception or sum of the SG function. As for the strategy, we can enumerate each location.
Code:
# Include <stdio. h> # include <string. h ># include <algorithm> using namespace STD; const int n = 205; int T, out [N], on, Len, SG [N]; char STR [N]; bool win () {for (INT I = 0; I <len-2; I ++) {If (STR [I] = 'X' & STR [I + 1] = 'X' & STR [I + 2] = 'X ') return true;} return false;} int Mex (int x) {bool vis [N]; int I, T; If (SG [x]! =-1) return SG [X]; If (x = 0) return SG [x] = 0; memset (VIS, false, sizeof (VIS )); for (INT I = 1; I <= x; I ++) {int T = Mex (max (0, I-3) ^ Mex (max (0, x-I-2); vis [T] = true;} For (INT I = 0; I <n; I ++) {If (vis [I]) continue; return SG [x] = I ;}} bool towin () {for (INT I = 0; I <Len; I ++) {If (STR [I] = '. ') {STR [I] = 'X'; If (WIN () {STR [I] = '. '; return false;} STR [I] = '. ';} int ans = 0, num = 0; For (INT I = 0; I <Len; I ++) {If (STR [I] = 'X' | (I> = 1 & STR [I-1] = 'X ') | (I> = 2 & STR [I-2] = 'X ') | (I + 1 <Len & STR [I + 1] = 'X ') | (I + 2 <Len & STR [I + 2] = 'X') {ans ^ = Mex (Num); num = 0 ;} else num ++;} ans ^ = Mex (Num); Return ans = 0;} void solve () {on = 0; Len = strlen (STR ); for (INT I = 0; I <Len; I ++) {If (STR [I]! = '. ') Continue; STR [I] = 'X'; If (WIN () | towin () out [ON ++] = I + 1; STR [I] = '. ';}} int main () {memset (SG,-1, sizeof (SG); scanf ("% d", & T); While (t --) {scanf ("% s", STR); solve (); If (on = 0) printf ("losing \ n "); else {printf ("winning \ n % d", out [0]); For (INT I = 1; I <on; I ++) printf ("% d ", out [I]); printf ("\ n") ;}} return 0 ;}