Poj 3537 crosses and crosses

Source: Internet
Author: User

Http://poj.org/problem? Id = 3537

Question:

The two draw X in turn on the 1 * n lattice. Each time they draw X on the blank lattice, if a player connects three X, the player wins. Whether your task is to determine whether it is a first-hand victory or a second-hand victory.

Ideas:

When you draw on paper, you will find that after you draw a grid, the two on the left and the two on the right cannot be painted (if any). That is to say, every time you draw a grid, five grids are excluded.

Therefore, it is divided into two parts: I-3 on the left and n-I-2 on the right. Use the SG function to solve the problem.


# Include <cstdio> # include <cstring> const int maxn = 2000 + 10; int SG [maxn]; int DFS (int n) {If (n <0) return 0; if (SG [N]! =-1) return SG [N]; bool vis [maxn]; memset (VIS, 0, sizeof (VIS); For (INT I = 1; I <= N; I ++) {vis [DFS (I-3) ^ DFS (n-I-2)] = 1 ;}for (INT I = 0; I <= N; I ++) {If (! Vis [I]) return SG [N] = I;} int main () {int N; memset (SG,-1, sizeof (SG); While (~ Scanf ("% d", & N) {printf ("% d \ n", DFS (n) = 0? 2: 1);} return 0 ;}


Poj 3537 crosses and crosses

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.