【贪心】【uva11520】 Fill the Square
填充正方形(Fill the Square, UVa 11520)
在一个n×n网格中填了一些大写字母,你的任务是把剩下的格子中也填满大写字母,使得任意两个相邻格子(即有公共边的格子)中的字母不同。如果有多种填法,则要求按照从上到下、从左到右的顺序把所有格子连接起来得到的字符串的字典序应该尽量小。
【输入格式】
输入的第一行为测试数据组数T。每组数据的第一行为整数n(n≤10),即网格的行数和列数;以下n行每行n个字符,表示整个网格。为了清晰起见,本题用小数点表示没有填字母的格子。
【输出格式】
对于每组数据,输出填满字母后的网格。
【样例输入】
2
3
...
...
...
3
...
A..
...
【样例输出】
Case 1:
ABA
BAB
ABA
Case 2:
BAB
ABA
BAB
水题一枚
上代码
#include<cstdio>
#include<cstring>
const int maxn=12;
char map[maxn][maxn];
int n;
int input()
{
char c;
memset(map,0,sizeof(map));
scanf("%d\n",&n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
scanf("%c",&map[i][j]);
scanf("%c",&c);
}
return 0;
}
int getans()
{
for(int j=1;j<=n;j++)
for(int i=1;i<=n;i++)
for(char k='A';k<='Z';k++)
{
if(map[i][j]=='.')
if(map[i-1][j]!=k&&map[i][j-1]!=k&&map[i][j+1]!=k&&map[i+1][j]!=k)
{ map[i][j]=k;break;}
else;
else break;
}
return 0;
}
int putans(int Case)
{
printf("Case %d:\n",Case);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
printf("%c",map[i][j]);
printf("\n");
}
}
int main()
{
int T,TT;
scanf("%d",&T);
TT=T;
while(T--)
{
input();
getans();
putans(TT-T);
}
return 0;
}
【贪心】【uva11520】 Fill 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(模拟)
题目链接:https://vjudge.net/problem/UVA-11520 这道题我们发现$n\leq 10$,所以直接进行暴力枚举. 因为根据字典序所以每个位置试一下即可,这样的复杂度不过也 ...
- UVa 11520 Fill the Square 填充正方形
在一个 n * n 网格中填了一些大写字母,你的任务是把剩下的格子中也填满大写字母,使得任意两个相邻格子(即有公共边的格子)中的字母不同.如果有多重填法,则要求按照从上到下,从左到右的顺序把所有格子连 ...
- UVa 11520 Fill the Square (水题,暴力)
题意:给n*n的格子里填上A-Z的字符,保证相邻字符不同,并且字典序最小. 析:直接从第一个格子开始暴力即可,每次判断上下左是不是相同即可. 代码如下: #pragma comment(linker, ...
- Gym 100531H Problem H. Hiking in the Hills 二分
Problem H. Hiking in the Hills 题目连接: http://codeforces.com/gym/100531/attachments Description Helen ...
- POJ2227(优先队列)
The Wedding Juicer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3440 Accepted: 155 ...
- OI 刷题记录——每周更新
每周日更新 2016.05.29 UVa中国麻将(Chinese Mahjong,Uva 11210) UVa新汉诺塔问题(A Different Task,Uva 10795) NOIP2012同余 ...
- [译]Vulkan教程(29)组合的Image采样器
[译]Vulkan教程(29)组合的Image采样器 Combined image sampler 组合的image采样器 Introduction 入门 We looked at descripto ...
随机推荐
- POJ 1469 ZOJ1140 二分匹配裸题
很裸,左点阵n,右点阵m 问最大匹配是否为n #include <cstdio> #include <cstring> #include <vector> usin ...
- POJ1742:Coins(多重背包)
Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar. ...
- PHP获取中英文混合字符串长度及截取
1.字符串长度 PHP获取中英文混合字符串长度的实现代码如下,1中文=1位,2英文=1位,可自行修改 /** * PHP获取字符串中英文混合长度 * @param $str string 字符串 * ...
- EffectiveC#11--选择foreach循环
1.C#的foreach语句可以为你的任何集合产生最好的迭代代码 不推荐如下写法(?原因未明白 作者意思是阻碍jit边界检测) int len = foo.Length; for ( int inde ...
- 虚拟机VirtualBox和Ubutu
虚拟机的作用1. 演示环境,可以安装各种演示环境,便于做各种例子: 2. 保证主机的快速运行,减少不必要的垃圾安装程序,偶尔使用的程序,或者测试用的程序在虚拟机上运行: 3. 避免每次重新安装,银行等 ...
- oracle中anyData数据类型的使用实例
---创建waterfallcreate or replace type waterfall is object(name varchar2(30),height number); --创建river ...
- MVC WEB api 自动生成文档
最近在一直在用webapi做接口给移动端用.但是让我纠结的时候每次新加接口或者改动接口的时候,就需要重新修改文档这让我很是苦恼.无意中发现.webapi居然有自动生成文档的功能....真是看见了救星啊 ...
- Obstack是C标准库里面对内存管理的GNU扩展
Obstack是C标准库里面对内存管理的GNU扩展 Obstack介绍 Obstack初始化 在Obstack中申请对象 释放对象 申请growing object 获取Obstack状态 数据对齐 ...
- linux搭建svn版本管理器
安装SVN [root@localhost modules]#yum install subversion 验证安装 检验已经安装的SVN版本信息[root@localhost modules]# s ...
- git diff 使用
1. 本地工作目录与远程仓库对比(所有改动过的文件) git diff HEAD (HEAD指向最新一次的提交,即最新版本) 2. 之对比给定的文件 git diff -- filename //是 ...