题解:P12549 [UOI 2025] Gift for Anton
sacc
·
·
题解
题目传送门
题目分析
## 解决方法
设此块为 $map(i,j)$ 有三种构造:
这一块填 $0$ 那么 $map(i,j)=0$。
这一块填 $1$ 那么 $map(i+1,j)=map(i+2,j)=map(i,j+1)=map(i,j+2)=1$。
这一块填 $2$ 那么 $map(i+1,j+1)=map(i+2,j+1)=map(i+1,j+2)=map(i+2,j+2)=2$。
但注意,$i$ 和 $j$ 每次加 $3$。
可以用预处理算法预处后输出即可。
## AC代码
```cpp
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000007
#define int long long
int n,m;
int mapp[335][335];
int ii,jj;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
//预处理。
for(int i=0;i<=330;i+=3)
{
for(int j=0;j<=330;j+=3)
{
mapp[i][j]=0;
mapp[i+1][j]=mapp[i+2][j]=mapp[i][j+1]=mapp[i][j+2]=1;
mapp[i+1][j+1]=mapp[i+2][j+1]=mapp[i+1][j+2]=mapp[i+2][j+2]=2;
}
}
//特殊情况。
if(n%3==2)ii=1;
if(m%3==2)jj=1;
for(int i=ii;i<n+ii;i++)
{
for(int j=jj;j<m+jj;j++)
{
cout<<mapp[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
```