题意:给出 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. swift的属性与变量- Stored Properties and Instance Variables

    是一个概念 Stored Properties and Instance Variables If you have experience with Objective-C, you may know ...

  2. SaltStact自动化运维工具01

     什么是saltstackSaltstack是基于python开发的一套C/S架构配置管理工具使用SSL证书签方的方式进行认证管理底层使用ZeroMQ消息队列pub/sub方式通信    – 号称世界 ...

  3. 解决linux 升级高版本python3.7后yum不能使用的问题

    我们linux系统一般自带python2.7 版本,但是最近项目需求必须要上python3以上,对于用惯了python2的我来说,只能硬着头皮上了.下面是我的解决办法 which yum => ...

  4. 如何在php中优雅的地调用python程序

    1.准备工作   安装有python和php环境的电脑一台. 2.书写程序. php程序如下 我们也可以将exec('python test.py') 换成 system('python test.p ...

  5. Mysql5.7安装过程----win10

    ---恢复内容开始--- 1.Mysql官网:https://www.mysql.com/downloads/ 有两种下载方式:msi和zip压缩包 2.我下载的是zip压缩包,选择mysql com ...

  6. WEBGL学习【十二】鼠标操作场景

    <!DOCTYPE HTML> <html lang="en"> <head> <title>Listing 7-3 and 7-4 ...

  7. PuTTY_0.67.0.0工具链接linux

    1.虚拟机设置 在网络适配器中选中桥接模式,勾选复制物理网络链接状态(p)选项.点击确认. 2.开启虚拟机,检查是否安装有ssh服务器 a.查看是否启动ssh服务器 ps -a | grep ssh ...

  8. 关于mvc架构的浅谈

    MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用一种业务逻辑.数据.界面显示分离的方法组织代码 ...

  9. struct 模块解决 TCP黏包问题

    首先来看一下产生黏包现象的一段代码: # server.py 服务端 import socket ​ sk = socket.socket() sk.bind(('127.0.0.1',9000)) ...

  10. Linux-经常用到的几个命令

    -- |" 拷贝本地到远程 scp /serverdata/server/tomcat-uaac/webapps/dm.war root@172.16.7.123:/serverdata/s ...