题解:P14247 [CCPC 2024 Shandong I] 矩阵
\texttt{solve}
感觉这题很有意思,交一发题解。
你需要做的是把
考虑先给矩阵四个角填上不同的数,然后在第
此刻考虑矩阵中心如何填,不难发现直接拿首尾两列
发现刚好填
题解的具体填法是填左上角为
\texttt{code}
#include <bits/stdc++.h>
#define lint long long
#define endl '\n'
using namespace std;
const int N = 50+5;
int n,a[N][N];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
cout << "Yes" << endl;
a[1][1] = 1;
for(int i = 1; i <= n; i++){
for(int j = 2; j < n; j++)
a[i][j] = j;
}
for(int i = 2; i < n; i++)
a[i][1] = a[i][n] = i+n-2;
a[1][n] = (n<<1)-2;
a[n][1] = (n<<1)-1;
a[n][n] = (n<<1);
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++)
cout << a[i][j] << " ";
cout << endl;
}
return 0;
}