UVa 11520 Fill in the Square
题意:给出 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的更多相关文章
- uva 11520 - Fill the Square
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- Uva 11520 - Fill the Square 贪心 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVa 11520 Fill the Square 填充正方形
在一个 n * n 网格中填了一些大写字母,你的任务是把剩下的格子中也填满大写字母,使得任意两个相邻格子(即有公共边的格子)中的字母不同.如果有多重填法,则要求按照从上到下,从左到右的顺序把所有格子连 ...
- UVa 11520 Fill the Square (水题,暴力)
题意:给n*n的格子里填上A-Z的字符,保证相邻字符不同,并且字典序最小. 析:直接从第一个格子开始暴力即可,每次判断上下左是不是相同即可. 代码如下: #pragma comment(linker, ...
- UVA 11520 Fill the Square(模拟)
题目链接:https://vjudge.net/problem/UVA-11520 这道题我们发现$n\leq 10$,所以直接进行暴力枚举. 因为根据字典序所以每个位置试一下即可,这样的复杂度不过也 ...
- UVA 11520 填充正方形
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 10603 Fill(正确代码尽管非常搓,网上很多代码都不能AC)
题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=1544">click here~ ...
- UVA 10603 - Fill BFS~
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&c ...
- 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 ...
随机推荐
- (转)Bootstrap 之 Metronic 模板的学习之路 - (6)自定义和扩展
https://segmentfault.com/a/1190000006815041 前面我们将 Metronic 的结构和源码大致浏览了一遍,Metronic 整个文件包有三百多兆,在实际项目中, ...
- JavaScript 创建对象之单例、工厂、构造函数模式
01单例模式 首先看一个问题,我们要在程序中描述两个人,这两个人都有姓名和年龄,可能刚刚开始学习js的时候会写成这样: var name1 = 'iceman'; var age1 = 25; var ...
- day09网络编程
一 操作系统基础 操作系统:(Operating System,简称OS)是管理和控制计算机硬件与软件资源的计算机程序,是直接运行在“裸机”上的最基本的系统软件,任何其他软件都必须在操作系统的支持下才 ...
- JS 从36个数字里面随机抽取8个
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- xx-net安装配置
同学们,有没有因为不会FQ而痛苦?本小白就蛋疼了很久,今天终于把xx-netFQ工具给配置好了,拿出来和大家分享下. 首先,需要先下载xx-net,地址为:https://github.com/XX- ...
- windows电脑配置耳机只有一个耳朵响
也许你在工作,需要一个耳朵听同事的声音,一个耳朵听电脑的音乐,但是又不想另一个耳机头泄露声音,这样就有了想配置只有左/右单个耳机头会响的操作. 那么我们就开始配置吧,我这里以win10为例: 右击桌面 ...
- 经纬度计算两点间的距离,根据距离排序SQL
#java的Utilspublic class DistanceUtil { // 地球平均半径 private static final double EARTH_RADIUS = 6378137; ...
- STM32 ADC多通道转换DMA模式与非DMA模式两种方法(HAL库)
一.非DMA模式(转) 说明:这个是自己刚做的时候百度出来的,不是我自己做出来的,因为感觉有用就保存下来做学习用,原文链接:https://blog.csdn.net/qq_24815615/arti ...
- N - 畅通工程再续
N - 畅通工程再续 思路:zz #include<cmath> #include<cstdio> #include<cstring> #include<io ...
- CF802G Fake News (easy)
CF802G Fake News (easy) 题意翻译 给定一个字符串询问能否听过删除一些字母使其变为“heidi” 如果可以输出“YES”,不然为“NO” 题目描述 As it's the fir ...