题目链接
思路:
将图分成四块可以发现左上角的一块全为0,然后另外三块变化相同,所以分块分别递归另外三块即可。
ac代码:
#include <bits/stdc++.h>
using namespace std;
#define int long long
int A[2005][2005]; int n;
void qw(int x1,int x2,int y1,int y2){
if(x1==x2&&y1==y2) return ;
for(int i=x1;i<=(x1+x2)/2;i++){
for(int j=y1;j<=(y1+y2)/2;j++){
A[i][j]=0;
}
}
qw((x1+x2)/2+1,x2,y1,(y1+y2)/2); qw(x1,(x1+x2)/2,(y1+y2)/2+1,y2); qw((x1+x2)/2+1,x2,(y1+y2)/2+1,y2);
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n;
int x=1<<n;
for(int i=0;i<x;i++){
for(int j=0;j<x;j++){
A[i][j]=1;
}
}
qw(0,x-1,0,x-1);
for(int i=0;i<x;i++){
for(int j=0;j<x;j++){
cout<<A[i][j]<<" ";
}
cout<<endl;
}
return 0;
}