题解:P12549 [UOI 2025] Gift for Anton
StarTwinkleTwinkle · · 题解
容易得到
对于
0 1 1
1 2 2
1 2 2
我们发现这种构造方式延展性较强,故直接进行扩展即可。
代码:
#include <bits/stdc++.h>
using namespace std;
int n,m,a[1001][1001];
signed main(){
scanf("%d%d",&n,&m);
for(int i=0;i<=500;i+=3){
for(int j=0;j<=500;j+=3){
a[i][j]=0;
a[i+1][j]=a[i+2][j]=a[i][j+1]=a[i][j+2]=1;
a[i+1][j+1]=a[i+2][j+1]=a[i+1][j+2]=a[i+2][j+2]=2;
}
}
int fri=0,frj=0;
if(n%3==2)fri=1;
if(m%3==2)frj=1;
for(int i=fri;i<n+fri;++i){
for(int j=frj;j<m+frj;++j){
printf("%d ",a[i][j]);
}
printf("\n");
}
return 0;
}