这题我刚开始推出了n=1,2,3的情况,自己在大胆的猜测是奇偶性,发现A了;
后来打表也是奇偶性质;
打表代码:
View Code
1 #include2 #include 3 int n ; 4 int graph[1010][1010] ; 5 int tab[4][2] = {-1,0,1,0,0,-1,0,1} ; 6 int dfs (int x, int y) 7 { 8 int xx, yy, i, ans ; 9 for (i = 0 ; i < 4 ; i++) 10 { 11 xx = x + tab[i][0] ; 12 yy = y + tab[i][1] ; 13 if (xx < 0 || xx >= n) continue ; 14 if (yy < 0 || yy >= n) continue ; 15 if (graph[xx][yy]) continue ; 16 graph[xx][yy] = 1 ; 17 ans = dfs (xx, yy) ; 18 graph[xx][yy] = 0 ; 19 if (ans == 0) return 1 ; //如果下一点是必败点 那么该点一定是必胜点; 20 } 21 return 0 ;22 }23 int main ()24 { 25 graph[0][0] = 1 ; 26 for (n = 1 ; n <= 8 ; n++) 27 printf ("%d, %d\n", n, dfs (0,0)) ;28 system( "pause" ); 29 return 0;30 }
View Code
1 #include2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include