https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2515
http://7xjob4.com1.z0.glb.clouddn.com/c6a2a6f54f5a6c2cae2c82df2ec552f7
题意:填已有字母的格子,使相邻格子字母不同,使字典序尽量小
思路:从小到大排,检验是否可行
#include <bits/stdc++.h>
using namespace std; int n;
char grid[][]; int main()
{
int T,i,j,cas=;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=;i<n;i++)
{
scanf("%s",grid[i]);
}
for(i=;i<n;i++)
{
for(j=;j<n;j++)
{
if(grid[i][j]=='.')
{
for(char ch='A';ch<='Z';ch++)
{
bool flg=true;
if(i->= && grid[i-][j]==ch) flg=false;
if(i+<n && grid[i+][j]==ch) flg=false;
if(j->= && grid[i][j-]==ch) flg=false;
if(j+<n && grid[i][j+]==ch) flg=false;
if(flg)
{
grid[i][j]=ch;
break;
}
}
}
}
} printf("Case %d:\n",cas++);
for(i=;i<n;i++)
{
printf("%s\n",grid[i]);
}
}
return ;
}