题解:P12549 [UOI 2025] Gift for Anton
题目分析
对于一个
解决
首先不难想到
然后 观察 分析可知,存在一种万能的单位表格,可以直接填满整张表格,这样这题就做完了。
接下来就是如何构造了,首先这种单位表格要可以相互拼接,所以拼接时对应的数不能相同,然后就不难想到可以先放
可以得到以下单位表格(可能会有别的单位表格,不过本蒟蒻想不到)。
|0|1|1|
|:-:|:-:|:-:|
|1|2|2|
|1|2|2|
然后就是如何填表了,根据 蓝题(降绿了)了。
代码挺短的。
AC Code
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[210][210];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>m;
for(int i=1;i<=201;i+=3)
for(int j=1;j<=201;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 stn,stm;
if(n%3==2) stn=2;
else stn=1;
if(m%3==2) stm=2;
else stm=1;
//通过n和m模3的结果决定表格的开头
for(int i=stn;i-stn+1<=n;i++){
for(int j=stm;j-stm+1<=m;j++)
cout<<a[i][j]<<" ";
cout<<"\n";
}
return 0;
}
完结撒花。