Poj 3537 crosses and crosses

Source: Internet
Author: User

Poj_3537

It is difficult to express the status of connecting 3 X, so let's take a look at the status before connecting 3 X, as long as this status can be avoided.

When you draw a picture, you will find that there are only two types, namely x_x and _ XX _. In fact, we will gradually look forward to it, and the two players will definitely avoid coming out of the above situation. Therefore, when a player draws an X image, it is assumed that the situation is 12x34, and the number indicates the vacancy. To avoid the above situation, the four positions 1, 2, 3, and 4 cannot be taken. If they leave, they will lose, therefore, we can be equivalent to drawing an X, and then the X, together with the two grids on both sides of the left and right, is taken away. This will turn into a take and break game, for specific models of such games, refer to the essay "game theory.

As a result, we only need to regard a consecutive grid as a State. Each time we draw X, we either remove some grids at one end, you can either remove Five grids in the middle and divide the remaining grids into the left and right sides, or remove them if n is small. Then, use the Memory search function to obtain the SG function values of various States.

# Include <stdio. h>
# Include < String . H>
# Define Maxd 2010
Int SG [maxd], N;
Int DFS ( Int N)
{
If (SG [N]! =- 1 )
Return SG [N];
If (N <= 3 )
Return SG [N] = 1 ;
Int I, J, K, H [maxd];
Memset (H, 0 , Sizeof (H ));
For (I = 1 ; I <= N; I ++)
{
If (I> 3 )
{
If (I <n- 2 )
H [DFS (n-I- 2 ) ^ DFS (I- 3 )] = 1 ;
Else
H [DFS (I- 3 )] = 1 ;
}
Else
{
If (I <n- 2 )
H [DFS (n-I- 2 )] = 1 ;
Else
H [ 0 ] = 1 ;
}
}
For (I = 0 ; H [I]; I ++ );
Return SG [N] = I;
}
Int Main ()
{
Memset (SG ,- 1 , Sizeof (SG ));
While (Scanf ( " % D " , & N) = 1 )
Printf ( " % D \ n " , DFS (n )? 1 : 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.