填充正方形(Fill the Square, UVa 11520)

在一个n×n网格中填了一些大写字母,你的任务是把剩下的格子中也填满大写字母,使得任意两个相邻格子(即有公共边的格子)中的字母不同。如果有多种填法,则要求按照从上到下、从左到右的顺序把所有格子连接起来得到的字符串的字典序应该尽量小。

【输入格式】

输入的第一行为测试数据组数T。每组数据的第一行为整数nn≤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的更多相关文章

  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(模拟)

    题目链接:https://vjudge.net/problem/UVA-11520 这道题我们发现$n\leq 10$,所以直接进行暴力枚举. 因为根据字典序所以每个位置试一下即可,这样的复杂度不过也 ...

  4. UVa 11520 Fill the Square 填充正方形

    在一个 n * n 网格中填了一些大写字母,你的任务是把剩下的格子中也填满大写字母,使得任意两个相邻格子(即有公共边的格子)中的字母不同.如果有多重填法,则要求按照从上到下,从左到右的顺序把所有格子连 ...

  5. UVa 11520 Fill the Square (水题,暴力)

    题意:给n*n的格子里填上A-Z的字符,保证相邻字符不同,并且字典序最小. 析:直接从第一个格子开始暴力即可,每次判断上下左是不是相同即可. 代码如下: #pragma comment(linker, ...

  6. Gym 100531H Problem H. Hiking in the Hills 二分

    Problem H. Hiking in the Hills 题目连接: http://codeforces.com/gym/100531/attachments Description Helen ...

  7. POJ2227(优先队列)

    The Wedding Juicer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3440   Accepted: 155 ...

  8. OI 刷题记录——每周更新

    每周日更新 2016.05.29 UVa中国麻将(Chinese Mahjong,Uva 11210) UVa新汉诺塔问题(A Different Task,Uva 10795) NOIP2012同余 ...

  9. [译]Vulkan教程(29)组合的Image采样器

    [译]Vulkan教程(29)组合的Image采样器 Combined image sampler 组合的image采样器 Introduction 入门 We looked at descripto ...

随机推荐

  1. 使用maven编译的时候提示 maven-source 1.3 中不支持注释请使用 -source 5 或更高版本以启用注释的错误。

    在编译的模块的pom文件中加上 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins ...

  2. (转载)js获取JqueryString方法小结

    一.<script>urlinfo=window.location.href; //获取当前页面的urllen=urlinfo.length;//获取url的长度offset=urlinf ...

  3. JavaScript ----------------- 原型式继承

    思想:借助原型可以基于已有的对象创建新对象,同时还不必因此创建自定义类型.为了达到这个目的,看看下面的实现方式 function object(o){ function F(){ } F.protot ...

  4. javascript 切换动画

    function startMove(obj, json, fn) { clearInterval(obj.timer); obj.timer = setInterval(function() { v ...

  5. Android ---------- 清单文件中Activity常规设置

    <activity android:name="xxxxx" android:alwaysRetainTaskState="true" android:c ...

  6. XtraReport改变纸张方向

    XtraReport纸张方向改变可以通过修改Landscape属性: Landscape=true 为横向输出 Landscape=false 为纵向输出

  7. centos搭建zabbix

    安装一些依赖包,不同情况缺的包不同 yum install mysql-devel curl curl-devel net-snmp net-snmp-devel perl-DBI php-gd ph ...

  8. python运维开发(二十三)---tornado框架

    内容目录: 路由系统 模板引擎 cookie 加密cookie 自定义api 自定义session 自定义form表单验证 异步非阻塞 web聊天室实例 路由系统 路由系统其实就是 url 和 类 的 ...

  9. [转]MySQL 5.6 全局事务 ID(GTID)实现原理(三)

    原文连接:http://qing.blog.sina.com.cn/1757661907/68c3cad333002s5l.html 原文作者:淘长源 转载注明以上信息 这是 MySQL 5.6 全局 ...

  10. python2 ----函数字典的使用

    问题背景: 最近在用python2为sublime2写一个插件,其中有一个命令功能,就是输入不同的命令调用不同的函数,但是python不支持switch,只用ifelse的话感觉特别的low而且明显不 ...