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 ...
随机推荐
- Flask框架函数
title: flask学习笔记 subtitle: 1. flask框架函数 date: 2018-12-14 10:17:28 --- Flask学习 学习Miguel Grinberg的2017 ...
- priority_deque作为Timer时间队列底层容器的一些思考
https://www.bbsmax.com/A/D854VkZxzE/ 设置底层容器可以分离出两个逻辑上独立的问题: >如何存储构成优先级队列(容器)的实际元素,以及>如何组织这些元素以 ...
- 常用css和js内容
1.让一个200x200的div在不同分辨率屏幕上下左右居中. <div class="box"></div> <style type="t ...
- 在 vue-test-utils 中 mock 全局对象
vue-test-utils 提供了一种 mock 掉 Vue.prototype 的简单方式,不但对测试用例适用,也可以为所有测试设置默认的 mock. mocks 加载选项 mocks 加载选项 ...
- 为DK2应用程序迁移到Oculus CV1做好准备!
为DK2应用程序迁移到Oculus CV1做好准备! 本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/arti ...
- C#--职业路线图
非常好的一个C#的职业技术路线图
- FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT
FATAL ERROR in native method:JDWP No transports initialized,jvmtiError=AGENT_ERROR_TRANSPORT_INIT(19 ...
- MySql 基础学习笔记 1——概述与基本数据类型: 整型: 1)TINYINT 2)SMALLINT 3) MEDIUMINT 4)INT 5)BIGINT 主要是大小的差别 图 浮点型:命令
一.CMD中经常使用mysql相关命令 mysql -D, --database=name //打开数据库 --delimiter=name //指定分隔符 -h, --host=name // ...
- Auto property synthesis will not synthesize property 'delegate'; it will be implemented by its super
今天在XCode6.3上面重写TabBar的时候,自己定义tabBar的代理遇到的一个问题 在重写tabBar的代理的时候遇到了一个警告. 解决方法: 在.m文件里 警告消失
- codeforces Towers 题解
Little Vasya has received a young builder's kit. The kit consists of several wooden bars, the length ...