题意:给出 n*n的格子,把剩下的格子填上大写字母,使得任意两个相邻的格子的字母不同,且从上到下,从左到右的字典序最小

从A到Z枚举每个格子填哪一个字母,再判断是否合法

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int n;
char a[][]; int okl(int x,int y,char ch){
if(x- == - ) return ;
if(a[x-][y] == ch) return ;
return ;
} int okr(int x,int y,char ch){
if(x+ == n ) return ;
if(a[x+][y] == ch) return ;
return ;
} int oku(int x,int y,char ch){
if(y- == - ) return ;
if(a[x][y-] == ch) return ;
return ;
} int okd(int x,int y,char ch){
if(y+ == n ) return ;
if(a[x][y+] == ch) return ;
return ;
} int main(){
int T;
scanf("%d",&T);
int kase = ;
while(T--){
scanf("%d",&n);
for(int i = ; i < n;i++) cin>> a[i]; for(int i = ;i < n;i++){
for(int j =;j < n;j++){
for(char ch = 'A';ch <= 'Z';ch++){
if(okl(i,j,ch) && okr(i,j,ch) && oku(i,j,ch) && okd(i,j,ch) && a[i][j] == '.') {
a[i][j] = ch;
break;
}
}
}
}
printf("Case %d:\n",++kase);
for(int i = ;i<n;i++) printf("%s\n",a[i]);
}
return ;
}

UVa 11520 Fill in the Square的更多相关文章

  1. uva 11520 - Fill the Square

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  2. Uva 11520 - Fill the Square 贪心 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  3. UVa 11520 Fill the Square 填充正方形

    在一个 n * n 网格中填了一些大写字母,你的任务是把剩下的格子中也填满大写字母,使得任意两个相邻格子(即有公共边的格子)中的字母不同.如果有多重填法,则要求按照从上到下,从左到右的顺序把所有格子连 ...

  4. UVa 11520 Fill the Square (水题,暴力)

    题意:给n*n的格子里填上A-Z的字符,保证相邻字符不同,并且字典序最小. 析:直接从第一个格子开始暴力即可,每次判断上下左是不是相同即可. 代码如下: #pragma comment(linker, ...

  5. UVA 11520 Fill the Square(模拟)

    题目链接:https://vjudge.net/problem/UVA-11520 这道题我们发现$n\leq 10$,所以直接进行暴力枚举. 因为根据字典序所以每个位置试一下即可,这样的复杂度不过也 ...

  6. UVA 11520 填充正方形

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  7. UVA 10603 Fill(正确代码尽管非常搓,网上很多代码都不能AC)

    题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=1544">click here~ ...

  8. UVA 10603 - Fill BFS~

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&c ...

  9. UVa 10603 Fill [暴力枚举、路径搜索]

    10603 Fill There are three jugs with a volume of a, b and c liters. (a, b, and c are positive intege ...

随机推荐

  1. JDBCUtils 工具类

    import com.alibaba.druid.pool.DruidDataSourceFactory; import javax.sql.DataSource;import java.io.IOE ...

  2. Selenium3+python自动化008-常用操作

    一.元素常用操作 1. clear()            清除文本 2. send_keys()        模拟输入 3. click()            单击元素 4.get_attr ...

  3. 换个语言学一下 Golang (2)——基础语法

    Go 标记 Go 程序可以由多个标记组成,可以是关键字,标识符,常量,字符串,符号.比如下面的hello world就是由 6 个标记组成: 行分隔符 在 Go 程序中,一行代表一个语句结束.每个语句 ...

  4. python编写简单的html登陆页面(2)

    1  在python编写简单的html登陆页面(1)的基础上在延伸一下: 可以将动态分配数据,实现页面跳转功能: 2  跳转到新的页面:return render_template('home1.ht ...

  5. C语言提高 (4) 第四天 数组与数组作为参数时的数组指针

    1昨日回顾 const int 和 int const是一样的 const char *p;值不变 char * const p; 指针不能变 编译器对参数的退化: 第三种模型: 三级指针 三级指针局 ...

  6. [SDOI2018]战略游戏(圆方树+虚树)

    喜闻乐见的圆方树+虚树 图上不好做,先建出圆方树. 然后答案就是没被选到的且至少有两条边可以走到被选中的点的圆点的数量. 语文不好,但结论画画图即可得出. 然后套路建出虚树. 发现在虚树上DP可以得出 ...

  7. Rmq Problem mex

    求区间mex.莫队可做. 但如果强制在线,就可以用主席树做. 建立权值线段树,找每个数最后一次出现的位置.查询的时候找第r棵线段树最近出现位置在l之前的最小数即可.update的时候可以update这 ...

  8. nmcli connection modify eth1 ipv4.addr "192.168.31.23" ipv4.method manual

    nmcli connection modify eth1 ipv4.addr "192.168.31.23/24" ipv4.method manual 修改IP地址

  9. php中文乱码处理方法

    昨天在本地环境创建了一个文件,文件编码是UTF-8格式,打印一个简单的语句竟然出现了中文乱码,折腾了很久,才找到了原因. 乱码问题 昨天写了一个很简单的php输出中文页面,但是出现了乱码问题,第一反应 ...

  10. CSS中选择器优先级的权重计算

    CSS中选择器优先级的权重计算 先看一段代码,如下: a{ color: red; } #box a{ color: green; } [class="box"] a{ color ...