题解:CF1551D2 Domino (hard version)
TCY1234567 · · 题解
题解
恶心分讨题。
是否合法我们已经在上一道题目中知道了,所以说我们直接考虑如何构造。
首先是
对于
对于
代码
#include<bits/stdc++.h>
using namespace std;
int T;
int n,m,k;
int ans[210][210];
void init(){
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
ans[i][j] = -1;
}
}
}
void solve1(int nn,int mm,int kk){
bool typ1 = 0,typ2 = 0;
for(int i = 1;i<=nn;i+=2){
typ2^=1;
if(mm%4==2)typ1^=1;
for(int j = 1;j<=mm;j+=2){
typ1^=1;
if(kk!=0){
ans[i][j] = ans[i][j+1] = typ1;
ans[i+1][j] = ans[i+1][j+1] = typ1^1;
kk-=2;
}else{
ans[i][j] = ans[i+1][j] = typ2+2;
ans[i][j+1] = ans[i+1][j+1] = (typ2^1)+2;
}
}
}
}
void output(){
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
cout<<char(ans[i][j]+'a');
}
cout<<"\n";
}
}
void solve(){
cin>>n>>m>>k;
if(n%2==0&&m%2==0){
if(k%2==0){
cout<<"YES\n";
solve1(n,m,k);
output();
}else{
cout<<"NO\n";
}
}else if(n%2==0){
if(k<=n*(m-1)/2&&k%2==0){
cout<<"YES\n";
solve1(n,m-1,k);
for(int i = 1,typ = 0;i<=n;i+=2,typ^=1){
ans[i][m] = ans[i+1][m] = typ+4;
}
output();
}else{
cout<<"NO\n";
}
}else if(m%2==0){
int h = k-(m/2);
if(h>=0&&h%2==0){
cout<<"YES\n";
solve1(n-1,m,h);
for(int i = 1,typ = 0;i<=m;i+=2,typ^=1){
ans[n][i] = ans[n][i+1] = typ+4;
}
output();
}else{
cout<<"NO\n";
}
}
}
int main(){
cin>>T;
while(T--){
solve();
}
return 0;
}