HDU 2873 bomb game

Source: Internet
Author: User

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  ;} 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.