蛇形填数

 1 #include
 2 using namespace std;
 3 const int maxn=11;
 4 int a[maxn][maxn];
 5 int n, x, y, tot;
 6 int main()
 7 {
 8     scanf("%d", &n);
 9     tot = a[x][y=n-1]=1;
10     while(totn)
11     {
12         while(x+11][y]) a[++x][y]=++tot;
13         while(x-1>=0 && !a[x-1][y]) a[--x][y]=++tot;
14         while(y+11]) a[x][++y]=++tot;
15         while(y-1>=0 && !a[x][y-1]) a[x][--y]=++tot;
16     }//讨论情况
17     for(x=0; x)
18     {
19         for(y=0; y"%3.d", a[x][y]);//输出
20         printf("\n");
21     }
22     return 0;
23 }

就是把所有情况列举出来讨论,然后。。。再没了

哦,还有,初始位置要定好,旋转顺序不要反(根据题目要求) ~~@zdx~~

你可能感兴趣的:(蛇形填数)