平方矩阵1
平方矩阵2
曼哈顿距离
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>using namespace std;const int N = 110;int n;
int a[N][N];int main()
{while(cin >> n, n){for (int i = 0; i < n; i ++ )for (int j = 0; j < n; j ++ ){if (n % 2)a[i][j] = (n + 1) / 2 - max(abs(i - n / 2), abs(j - n / 2));else a[i][j] = (n - 1) / 2.0 - max(abs((n - 1) / 2.0- i), abs((n - 1) / 2.0 - j)) + 1;}for (int i = 0; i < n; i ++ ){for (int j = 0; j < n; j ++ ) cout << a[i][j] << ' ';cout << endl;}cout << endl;}return 0;
}
2 2 2 2 2
2 1 1 1 2
2 1 0 1 2
2 1 1 1 2
2 2 2 2 2
while True:n = int(input())if not(n): breakfor i in range(n):for j in range(n):print(min(j, n - j - 1, i, n - i - 1) + 1, end = ' ')print()print()11 1
1 11 1 1
1 2 1
1 1 11 1 1 1
1 2 2 1
1 2 2 1
1 1 1 11 1 1 1 1
1 2 2 2 1
1 2 3 2 1
1 2 2 2 1
1 1 1 1 1