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 ...
随机推荐
- 8 Mistakes to Avoid while Using RxSwift. Part 1
Part 1: not disposing a subscription Judging by the number of talks, articles and discussions relate ...
- codeforces 468B two set(并查集)
链接 B. Two Sets 题意 给两个集合A B,两个数a b,n个数x,分配n个数到两个集合,要求x , a-x在同一个集合,x , b-x在同一个集合,属于A集合的数输出0,B的输出1,无解输 ...
- php进程控制
1 POSIX扩展 posix_access($file,$mode) 查看文件的访问权限,可以由is_readable等几个函数代替 posix_errno() 返回posix函数执 ...
- python 多线程处理框架
多线程处理框架 python2.7 python3.5 多线程通用任务处理型驱动框架 probe_type 探测类型rtsp或者http task_queue 任务队列 task_handler 任务 ...
- redis 零散知识
1.单线程 2.默认 16 个库.0~15 3.select :切换数据库 4.DBsize :查看当前数据库的数量 5.keys * :查看当前库的所有 key 6.keys k? :问号是占位符 ...
- HDU 2439 The Mussels
The Mussels Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID ...
- C++ "#"的作用和用法
本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/48879093 1 #和##的作用和用法 ...
- spring bean的作用域和自动装配
1 Bean的作用域 l singleton单列:整个容器中只有一个对象实例,每次去访问都是访问同一个对象 默认是单列 l prototype原型: 每次获取bean都产生一个新的对象,比如Ac ...
- telnet允许root用户登录
默认情况下,linux不允许root用户以telnet方式登录linux主机,若要允许root用户登录,可采取以下3种方法之一: 1.修改login文件 redhat中对于远程登录的限制体现在/ ...
- POJ 1950
直接DFS,因为实在没想到什么剪枝了... 注意一点是,10.11使用的是1011哦 #include <iostream> #include <cstdio> #includ ...