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