题目描述
题目较难。
样例
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn = 150;
int a[maxn][maxn];
int main()
{
int n, m;
cin >> n >> m;
memset(a, 0, sizeof(a));
int x = 0, y = 0;
int cnt = 1;
a[x][y] = cnt;
while (cnt < n * m )
{
while (y + 1 < m && !a[x][y + 1]) a[x][ ++ y] = ++ cnt;
while (x + 1 < n && !a[x + 1][y]) a[ ++ x][y] = ++ cnt;
while (y - 1 >= 0 && !a[x][y - 1]) a[x][ -- y] = ++ cnt;
while (x - 1 >= 0 && !a[x - 1][y]) a[ -- x][y] = ++ cnt;
}
for (int i = 0; i < n; i ++ )
{
for (int j = 0; j < m; j ++ )
{
cout << a[i][j] << " ";
}
cout << endl;
}
return 0;
}