Uva 11520 - Fill the Square 贪心 难度: 0
题目
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的更多相关文章
- 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 填充正方形
在一个 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 11134 - Fabled Rooks 优先队列,贪心 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVa 11520 Fill in the Square
题意:给出 n*n的格子,把剩下的格子填上大写字母,使得任意两个相邻的格子的字母不同,且从上到下,从左到右的字典序最小 从A到Z枚举每个格子填哪一个字母,再判断是否合法 #include<ios ...
- UVa 10970 - Big Chocolate 水题 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVa 11210 - Chinese Mahjong 模拟, 枚举 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- hdu 3697 10 福州 现场 H - Selecting courses 贪心 难度:0
Description A new Semester is coming and students are troubling for selecting courses. Students ...
随机推荐
- RTTI(运行时类型识别),typeid,dynamic_cast
dynamic_cast注意: 1.只能应用于指针和引用的转换: 2.要转换的类型中必须包含虚函数: 3.转换成功则返回地址,如果失败则返回NULL: 参见项目:RTTI
- (转)Qt中图片相对位置的引用
原文作者:locky1218 原文地址:https://blog.csdn.net/locky1218/article/details/9749703/ 一般使用相对位置的时候可能无法显示图片,可 ...
- 第 6 章 存储 - 042 - 用 volume container 共享数据
volume container volume container 是专门为其他容器提供 volume 的容器.它提供的卷可以是 bind mount,也可以是 docker managed volu ...
- Redis持久化AOF和RDB对比
RDB持久化 AOF持久化 全量备份,一次保存整个数据库 增量备份,一次保存一个修改数据库的命令 保存的间隔较长 保存的间隔默认一秒 数据还原速度快 数据还原速度一般 save会阻塞,但bgsave或 ...
- 如何知道我 的python是32位还是64位的?
方法一: 打开IDLE,看第一行提示,例如: 32位系统是这样的 Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:38:48) [MSC v.19 ...
- English trip V1 - B 19. Life of Confucius 孔子的生活 Teacher:Patrick Key:
In this lesson you will learn to describe a daily routine. (日常生活) 课上内容(Lesson) 词汇(Key Word ) contrac ...
- WCF初见之SQL数据库的增删改查
1.首先要连接数据库,自然要有数据库啦,创建一个数据库表Login,并插入一个数据: --创建数据库表login CREATE TABLE Login ( UName VARCHAR(20) PRIM ...
- 378. Kth Smallest Element in a Sorted Matrix(java,优先队列)
题目: Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the ...
- arguments.callee用法
arguments.callee 在哪一个函数中运行,它就代表哪一个函数. 一般用在匿名函数中. 在匿名函数中有时会需要自己调用自己,但是由于是匿名函数,没有名子,无名可调. 这时就可以用argume ...
- 把url链接转换成二维码的工具类
import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.io ...