题目

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

题意

n*n矩阵中填入大写字母,n <= 10,要求从上到下从左到右字母序最小,相邻格子字母不同

思路

如刘书思路,状态比较小,不会导致矛盾。

感想

1. 状态较小

代码

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#define LOCAL_DEBUG
using namespace std;
typedef pair<double, int> MyPair;
const int MAXN = ;
int dx[] = { , -, , };
int dy[] = { , , , - };
char maze[MAXN][MAXN];
bool used[];
void fillin(int i, int j, int n) {
memset(used, , sizeof used);
for (int di = ; di < ; di++) {
int tx = i + dx[di];
int ty = j + dy[di];
if ( > tx || tx >= n)continue;
if ( > ty || ty >= n)continue;
if (maze[tx][ty] == '.')continue;
used[maze[tx][ty] - 'A'] = true;
}
} int main() {
#ifdef LOCAL_DEBUG
freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\input.txt", "r", stdin);
//freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\output.txt", "w", stdout);
#endif // LOCAL_DEBUG
int T;
scanf("%d", &T);
for (int ti = ; ti <= T; ti++) {
int n;
scanf("%d", &n);
for (int i = ; i < n; i++)scanf("%s", maze + i);
for (int i = ; i < n; i++) {
for (int j = ; j < n; j++) {
if (maze[i][j] != '.')continue;
fillin(i, j, n);
for (char c = 'A'; c <= 'Z'; c++) {
if (!used[c - 'A']) {
maze[i][j] = c;
break;
}
}
}
}
printf("Case %d:\n", ti);
for (int i = ; i < n; i++)printf("%s\n", maze[i]); } return ;
}

Uva 11520 - Fill the Square 贪心 难度: 0的更多相关文章

  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 填充正方形

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

  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 11134 - Fabled Rooks 优先队列,贪心 难度: 0

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

  6. UVa 11520 Fill in the Square

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

  7. UVa 10970 - Big Chocolate 水题 难度: 0

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

  8. UVa 11210 - Chinese Mahjong 模拟, 枚举 难度: 0

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

  9. hdu 3697 10 福州 现场 H - Selecting courses 贪心 难度:0

    Description     A new Semester is coming and students are troubling for selecting courses. Students ...

随机推荐

  1. github下载文件和文件夹

    1.建议安装的插件.Octo mate在你的github的单个文件页面会出现download的下载按钮. 2.octo tree 右侧多一个github readme.md的一个菜单. 3.下载文件夹 ...

  2. R语言函数总结(转)

    R语言特征 对大小写敏感 通常,数字,字母,. 和 _都是允许的(在一些国家还包括重音字母).不过,一个命名必须以 . 或者字母开头,并且如果以 . 开头,第二个字符不允许是数字. 基本命令要么是表达 ...

  3. Enable SMB2 on the Client

    HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\LanmanWorkstation edit DependOnService and add ...

  4. Onsen UI快速入门 --Onsen UI

     一.什么是Onsen UI? 1.一系列专为移动应用程序设计的丰富UI组件.具有遵循原生iOS和Android设计标准的即时实现功能.免费使用,100%开源软件(Apache v2许可证).Onse ...

  5. linux文件管理之查找

    1 文件查找 1.1 which 查找可执行文件的路径which是通过 PATH环境变量到该路径内查找可执行文件,所以基本的功能是寻找可执行文件[root@www ~]# which [-a] com ...

  6. hdoj5785

    题意:略 先用题解的办法,manacher,然后tag,add数组.但是比较难办的是manacher加了新的字符.这样的话cntL和cntR不是实际的值,但是没关系,原本的字符都在奇数位置,这样cnt ...

  7. python3-----多进程、多线程、多协程

    目前计算机程序一般会遇到两类I/O:硬盘I/O和网络I/O.我就针对网络I/O的场景分析下python3下进程.线程.协程效率的对比.进程采用multiprocessing.Pool进程池,线程是自己 ...

  8. Scrapy - CrawlSpider爬虫

    crawlSpider 爬虫 思路: 从response中提取满足某个条件的url地址,发送给引擎,同时能够指定callback函数. 1. 创建项目 scrapy startproject mysp ...

  9. [java]转:String Date Calendar之间的转换

    String Date Calendar之间的转换 String Date Calendar  1.Calendar 转化 String Calendar calendat = Calendar.ge ...

  10. php7配置多线程

    1.下载pthreads 文件  http://windows.php.net/downloads/pecl/releases/pthreads/3.1.5/ 2.把   pthreadVC2.dll ...