这题妙啊
首先不难发现, 是无解的。
可以非常方便地构造:
e..
e..
.ee然后考虑更大的怎么办。
我们考虑构造多米诺数量为 的矩阵:
:
orzz
oree
eero
zzro:
orrzz
oe..e
ae..e
a.eez
oorrz:
oorrzz
.e.e.e
.e.e.e
e.e.e.
e.e.e.
oorrzz:
.oorrzz
oaee...
oa.a...
reea...
r...eaa
z...e.e
z...aae打完这些表后,聪明的观众可能就会说:我会做了!
对于 的那些表格,我们只需要用上面四个凑就行了。将这些东西放在对角线上就可以了。
比如,对于 ,我们可以用一个 和一个 来凑:
orzz.....
oree.....
eero.....
zzro.....
....orrzz
....oe..e
....ae..e
....a.eez
....oorrz更大的也用类似的方法凑就行了。大概就先将 算出最后凑上哪一个,然后再一直凑 直到凑到 就行了。
:
const string S4[4] = {"abcc", "abdd", "ccab", "ddab"};
const string S5[5] = {"abbcc", "ad..a", "bd..a", "b.eez", "oorrz"};
const string S6[6] = {"oorrzz", ".a.b.c", ".a.b.c", "d.e.f.", "d.e.f.", "oorrzz"};
const string S7[7] = {".oorrzz", "oabb...", "oa.c...", "rddc...", "r...abb", "z...a.c", "z...ddc"};
char s[1010][1010];
inline void solve(int&n, int x) {
if(x == 4)
for(int i = 0; i < x; i++)
for(int j = 0; j < x; j++)
s[n + i][n + j] = S4[i][j];
if(x == 5)
for(int i = 0; i < x; i++)
for(int j = 0; j < x; j++)
s[n + i][n + j] = S5[i][j];
if(x == 6)
for(int i = 0; i < x; i++)
for(int j = 0; j < x; j++)
s[n + i][n + j] = S6[i][j];
if(x == 7)
for(int i = 0; i < x; i++)
for(int j = 0; j < x; j++)
s[n + i][n + j] = S7[i][j];
n += x;
}
int main() {
int n = ri;
if(n <= 2) return puts("-1"), 0;
if(n == 3) {
puts("a..");
puts("a..");
puts(".bb");
return 0;
}
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
s[i][j] = '.';
int x = n % 4, N = 1;
if(x == 0) solve(N, 4);
if(x == 1) solve(N, 5);
if(x == 2) solve(N, 6);
if(x == 3) solve(N, 7);
while(N <= n) solve(N, 4);
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++)
putchar(s[i][j]);
puts("");
}
return 0;
}