The grundy value of poj 3537 Crosses and Crosses Game Theory

Source: Internet
Author: User

The grundy value of poj 3537 Crosses and Crosses Game Theory

Question:

For a 1 * n grid, take turns on the top of the Cross, first draw three consecutive cross-forks to win, and ask whether the first hand wins or loses.

Analysis:

Find the grundy value of the status (that is, the sg value). For details, see the code. Why do you want to think about it? I can only think about it. (others say they want to see game theory ).

Code:

 

// Poj 3537 // sep9 # include

 
  
# Include

  
   
Using namespace std; int grundy [2048]; int h [2048]; int get_grundy (int n) {if (n <0) return 0; if (grundy [n]! =-1) return grundy [n]; int h [2048]; memset (h, 0, sizeof (h); for (int I = 1; I <= n; + + I) {int t = get_grundy (I-3) ^ get_grundy (n-i-2); h [t] = 1 ;}int I; for (I = 0; h [I]; ++ I); return grundy [n] = I;} int main () {int n; memset (grundy,-1, sizeof (grundy )); grundy [0] = 0, grundy [1] = 1, grundy [2] = 1, grundy [3] = 1; while (scanf ("% d", & n) = 1) if (get_grundy (n )! = 0) puts ("1"); elseputs ("2"); 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.