Hdu_2873
Since the remaining bombs generated after each bomb explosion will shrink to the corner, If we regard the bomb status as a node, it is actually a fair combination game with a directed acyclic graph, therefore, the SG function theory can be used to solve the problem. Because each bomb is independent, the SG function values of each bomb can be calculated by means of memory-based search, and then the SG function values of the entire situation are the same or different.
# Include <stdio. h> # Include < String . H> # Define Maxn 60 # Define Maxd 2510 Int N, m, SG [maxn] [maxn]; Char B [maxn]; Void Prep (){ Int I; memset (SG, - 1 , Sizeof (SG); SG [ 1 ] [ 1 ] = 0 ; For (I = 2 ; I <= 50 ; I ++ ) SG [ 1 ] [I] = SG [I] [ 1 ] = I- 1 ;} Int DFS ( Int X, Int Y ){ If (SG [x] [Y]! =- 1 ) Return SG [x] [Y]; Int I, j, H [maxd]; memset (H, 0 ,Sizeof (H )); For (I = 1 ; I <X; I ++ ) For (J = 1 ; J <Y; j ++) H [DFS (I, Y) ^ DFS (x, j)] = 1 ; For (I = 0 ; H [I]; I ++ ); Return SG [x] [Y] = I ;} Void Solve (){ Int I, j, ANS = 0 ; For (I = 1 ; I <= N; I ++ ) {Scanf ( " % S " , B + 1 ); For (J = 1 ; J <= m; j ++) If (B [J] = ' # ' ) Ans ^ = DFS (I, j);} printf ( " % S \ n " , ANS? " John " : " Jack " );} Int Main () {prep (); While (Scanf ( " % D " , & N ,& M), n) solve (); Return 0 ;}