#include <iostream> #include<cmath> #include "algorithm" #include "cstdio" #include "stack" using namespace std; //bool cmp(const int a, const int b) //{ // return a<b; //} int main() { int n; cin >> n; int a[n][n]; int i,j,k; a[n/2][n/2] = 1; for(i = n,k = n;i>1 && k > n/2; i = i-2 ,k --) { for(j = 0;j<i-1;j++) { a[k-2-j][k-1] = (i-2)*(i-2) + 1 + j; a[n-k][k-2-j] = (i-2)*(i-2) + i + j; a[j+1+n-k][n-k] = (i-2)*(i-2) + 2*i - 1 + j; a[k-1][j+1+n-k] = (i-2)*(i-2) + 3*i - 2 + j; } }int sum = 0; for(i=0;i<n;i++) { sum = sum + a[i][i]; sum = sum + a[i][n-i-1]; } for(i=0;i<n;i++) { for(j=0;j<n;j++) cout << a[i][j]<<" "; cout << endl; } cout << sum-1 << endl; return 0; }
写了一个小时不想就这么删了,虽然没啥用