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

直接暴力走起就OK。因为,需要填的格子最多就是 A、B、C、D、E 这五个字母。所以直接暴力也就 O(n2

因为要保证字符串的字典序最小,所以就从第一行第一列开始,一行一行的暴就搞定了。其他的就不说了,简单的水题。

附AC代码:

   1: #include <stdio.h>

   2: #include <math.h>

   3: #include <iostream>

   4: #include <cstdarg>

   5: #include <algorithm>

   6: #include <string.h>

   7: #include <stdlib.h>

   8: #include <string>

   9: #include <list>

  10: #include <vector>

  11: #include <map>

  12: #define LL long long

  13: #define M(a) memset(a, 0, sizeof(a))

  14: using namespace std;

  15:  

  16: void Clean(int count, ...)

  17: {

  18:     va_list arg_ptr;

  19:     va_start (arg_ptr, count);

  20:     for (int i = 0; i < count; i++)

  21:         M(va_arg(arg_ptr, int*));

  22:     va_end(arg_ptr);

  23: }

  24:  

  25: char buf[19][19];

  26:  

  27: char Deal(int a, int b)

  28: {

  29:     for (char tmp = 'A'; tmp <= 'Z'; tmp++)

  30:     {

  31:         if (buf[a - 1][b] == tmp) continue;

  32:         else if (buf[a + 1][b] == tmp) continue;

  33:         else if (buf[a][b - 1] == tmp) continue;

  34:         else if (buf[a][b + 1] == tmp) continue;

  35:         else return tmp;

  36:     }

  37: }

  38:  

  39: int main()

  40: {

  41:     int T, n, cnt = 1;

  42:     scanf("%d", &T);

  43:     while(T--)

  44:     {

  45:         scanf("%d", &n);

  46:         Clean(1, buf);

  47:         char *input = &buf[1][1];

  48:         for (int i = 1; i <= n; i++)

  49:         {

  50:             input = &buf[i][1];

  51:             scanf("%s", input);

  52:         }

  53:         for(int i = 1; i <= n; i++)

  54:         {

  55:             for (int j = 1; j <= n; j++)

  56:             {

  57:                 if (buf[i][j] == '.')

  58:                     buf[i][j] = Deal(i, j);

  59:             }

  60:         }

  61:         printf("Case %d:\n", cnt++);

  62:         for(int i = 1; i <= n; i++)

  63:         {

  64:             for (int j = 1; j <= n; j++)

  65:                 printf("%c", buf[i][j]);

  66:             puts("");

  67:         }

  68:     }

  69:     return 0;

  70: }

UVa 11520 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 (水题,暴力)

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

  4. UVA 11520 Fill the Square(模拟)

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

  5. UVa 11520 Fill in the Square

    题意:给出 n*n的格子,把剩下的格子填上大写字母,使得任意两个相邻的格子的字母不同,且从上到下,从左到右的字典序最小 从A到Z枚举每个格子填哪一个字母,再判断是否合法 #include<ios ...

  6. 【贪心】【uva11520】 Fill the Square

    填充正方形(Fill the Square, UVa 11520) 在一个n×n网格中填了一些大写字母,你的任务是把剩下的格子中也填满大写字母,使得任意两个相邻格子(即有公共边的格子)中的字母不同.如 ...

  7. bzoj1661[Usaco2006 Nov]Big Square 巨大正方形*

    bzoj1661[Usaco2006 Nov]Big Square 巨大正方形 题意: n*n的图中有一些J点,一些B点和一些空白点,问在空白点添加一个J点所能得到的有4个J点组成最大正方形面积.n≤ ...

  8. UVA 11520 填充正方形

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. Uva 填充正方形

    暴力出奇迹 #include<iostream> #include<cstdio> using namespace std; +; int T,n; char S[maxn][ ...

随机推荐

  1. angularJS之$watch、$digest和$apply方法

    最近项目上使用了比较多的angular JS,一直都对它感觉比较陌生,总觉得有点反直觉,这段时间,准备下定决心弄明白,这个框架到底是怎么一回事,以及它的工作原理,生命周期……一点一点的啃完它吧.首先, ...

  2. Linux command: usermod -- 改变用户状态

    应用举例: 1. usermod -g newuser newuser force use GROUP as new primary group. 一般时候是默认的,也是必须的(不能更改).2. 指定 ...

  3. python 详解re模块

    正则表达式的元字符有. ^ $ * ? { [ ] | ( ).表示任意字符[]用来匹配一个指定的字符类别,所谓的字符类别就是你想匹配的一个字符集,对于字符集中的字符可以理解成或的关系.^ 如果放在字 ...

  4. Ubuntu--服务器版本系统安装图解教程

    附Ubuntu Server 13.04系统镜像下载地址: 32位:http://mirrors.163.com/ubuntu-releases/13.04/ubuntu-13.04-server-i ...

  5. MDK4.6和J-LINK调试出现问题,软件自动关闭,在网上收集整理的解决办法

    MDK4.6配J-LINK调试时提示升级,升级完成后,弹出下图提示框后,软件自动退出. 提示原因:由于MDK4.6能识别山寨JLINK导致.网络牛人分析如下: 今天将Keil MDK升级到了V4.54 ...

  6. Outlook与Hotmail的设置

    最近研究邮件备份,首先要使用客户端下载邮件,碰到不少问题:1. HOTMAIL GMAIL SINA的POP/IMAP默认居然都是关闭的,必须改成开放才行. GMAIL改成开放以后还是没有成功,好像还 ...

  7. PHPCMS V9添加模板自定义全局变量

    在我们使用PHPCMS V9的制作网站模板的时候,使用全局模板变量能轻松调用,使用起来非常方便,而且可以统一修改,方便维护. 下面就来讲一下在PHPCMS V9中如何添加自定义全局变量. 修改网站sy ...

  8. MyBatis学习总结_03_优化MyBatis配置文件中的配置

    一.连接数据库的配置单独放在一个properties文件中 之前,我们是直接将数据库的连接配置信息写在了MyBatis的conf.xml文件中,如下: 1 <?xml version=" ...

  9. POJ1019——Number Sequence(大数处理)

    Number Sequence DescriptionA single positive integer i is given. Write a program to find the digit l ...

  10. stanford-postagger中文词性标注

    安装 系统需要安装Java1.6+ http://nlp.stanford.edu/software/tagger.shtml 下载Download full Stanford Tagger vers ...