#include <stdio.h>
#define MAXN 110
int a[MAXN][MAXN], m, n;
void input(){
scanf("%d %d", &n, &m);
}
void initial(){
int i;
for (i = 0; i<=n+1; ++i){
a[i][0]=-1;
a[i][m+1]=-1;
}
for (i = 0; i<=m+1; ++i){
a[0][i]=-1;
a[n+1][i]=-1;
}
}
void solve(){
int dx[] = {-1, 0 , 1, 0};
int dy[] = {0, 1, 0, -1};
int tx = 1, ty = 1, dir = 0, i;
a[1][1] = 1;
for (i = 2; i<=n*m; ++i){
while (a[tx+dx[dir]][ty+dy[dir]]){
dir = (dir+1)%4;
}
tx = tx + dx[dir];
ty = ty + dy[dir];
a[tx][ty] = i;
}
}
void output(){
int i, j;
for (i = 1; i<=n; ++i){
for (j = 1; j<=m; ++j){
printf("%4d ", a[i][j]);
}
printf("\n");
}
}
int main(){
freopen("D:\input.txt", "r", stdin);
freopen("D:\output.txt", "w", stdout);
input();
initial();
solve();
output();
return 0;
}
|