Fill the Square UVA - 11520
题意:
在一个n x n的网络中填写一些大写字母,你的任务是把剩下的格子中也填满大写字母。
要求每个格子相邻之间不能相同。
思路:
暴力即可。
AC
#include <iostream>
#include <bits/stdc++.h>
#define For(i,x,y) for(int i=(x); i<=(y); i++)
#define fori(i,x,y) for(int i=(x); i<(y); i++)
#define rep(i,y,x) for(int i=(y); i>=(x); i--)
#define mst(x,a) memset(x,a,sizeof(x))
#define pb push_back
#define sz(a) (int)a.size()
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int>pa;
typedef pair<ll,ll>pai;
char s[20][20];
int n;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int main()
{
int tt, caseno = 0; scanf("%d", &tt);//ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
while(tt--){
scanf("%d", &n);
For(i,1,n)scanf("%s", s[i]+1);
For(i,1,n)For(j,1,n){
if(s[i][j]=='.'){
fori(k,0,26){
bool ok = true;
char ch = k+'A';
fori(dr,0,4){
int tx = i+dx[dr],ty = j+dy[dr];
if(tx>=1 && tx<=n && ty>=1 && ty<=n &&ch==s[tx][ty])ok = false;
}
if(ok){
s[i][j] = ch;
break;
}
}
}
}
printf("Case %d:\n", ++caseno);
For(i,1,n)printf("%s\n", s[i]+1);
}
return 0;
}