贪心,从上到下,从左到右,能填A则填A,否则试B...
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int INF =0x3f3f3f3f;
const int maxm=100000 ;
int n,m;
char s[maxm+5];
char a[12][maxm+5];
int dir[4][2]={{-1,0},{+1,0},{0,-1},{0,+1} };
bool vis[30];
bool in(int &y,int &x)
{
return 0<=y&&y<n&&0<=x&&x<m;
}
char find()
{
for(int i=0;i<26;i++)
{
if(!vis[i])
{
return 'A'+i;
}
}
}
void work()
{
for(int y=0;y<n;y++)
{
for(int x=0;x<m;x++)
{
if(a[y][x]!='.') continue;
memset(vis,0,sizeof vis);
for(int j=0;j<4;j++)
{
int ty=y+dir[j][0];
int tx=x+dir[j][1];
if(!in(ty,tx)||a[ty][tx]=='.') continue;
int t=a[ty][tx]-'A';
vis[t]=1;
}
char ch=find();
a[y][x]=ch;
}
}
}
int main()
{
int T,kase=0;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%s",a[i]);
}
m=strlen(a[0]);
work();
printf("Case %d:\n",++kase);
for(int y=0;y<n;y++)
{
for(int x=0;x<m;x++)
{
putchar(a[y][x]);
}
putchar('\n');
}
}
return 0;
}