题解:B4162 [BCSP-X 2024 12 月初中组] 稳定原子
这道题分类讨论一下即可,考虑的是
如果 No。
如果 Yes,最外面的一圈填上
以下是这道题的 AC 代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1010;
int a[N][N];
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t;
cin>>t;
while(t--){
int n;
cin>>n;
if(n%2==1){
cout<<"No\n";
}else{
cout<<"Yes\n";
int l=1,r=n,flag=1;
while(l<r){
for(int i=l;i<=r;i++){
for(int j=l;j<=r;j++){
a[i][j]=flag;
}
}
flag=1-flag;
l++,r--;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cout<<a[i][j]<<" ";
}
cout<<"\n";
}
}
}
return 0;
}