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 ...
随机推荐
- ftp服务器搭建(离线安装vsftpd),配置
1.下载vsftp:http://rpmfind.net/linux/rpm2html/search.php?query=vsftpd(x86-64) 2.检查是否已经安装了vsftp rpm -qa ...
- python 多进程和多线程
在计算大量数据时,可以使用多进程 多线程机制来加速计算 多进程 import multiprocessing import os def run_proc(name): print('Child pr ...
- Python全栈开发-Day8-Socket网络编程
本节内容 断言 Socket构建框架 ftp构建框架 Socket粘包 Socket介绍 Socket参数介绍 基本Socket实例 通过Socket实现简单SSH SocketServer 支持多用 ...
- fiddler学习笔记&&基本使用
周末在网上找了些fiddler相关的资料来看,学习下如何使用这个工具(平时接口测试用得比较多,在没有接口文档的情况下,可以通过抓包工具来提取需要测试的接口,ps.好久没写博客了,争取5月结束前再写2篇 ...
- 雷林鹏分享:现实生活中的 XML
现实生活中的 XML 如何使用 XML 来交换信息的一些实例. 实例:XML 新闻 XMLNews 是用于交换新闻和其他信息的规范. 对新闻的供求双方来说,通过使用这种标准,可以使各种类型的新闻信息通 ...
- python Deep learning 学习笔记
https://www.cnblogs.com/zhhfan/p/10300012.html
- Inotify&Sersync文件监视工具配置
一.Inotify介绍:一共安装2个工具(命令),即inotifywait和inotifywatchinotifywait:在被监控的文件或目录上等待特定文件系统事件(open.close.delet ...
- 如何抓取Amazon大图
https://www.douban.com/note/277033391/ 進入到日本Amazon看到某些商品有預覽圖可以放大欣賞,當你想要右鍵下載卻發現只得到空白圖或白邊圖.縮圖.切割圖,究竟原圖 ...
- kernel_thread简析
1.3.100static inline pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags){ lon ...
- P3489 付公主的背包
题意:n<=1e5,m<=1e5,跑n个物品1到m容量的完全背包. 考虑暴力的做法就是把一些1/(1+x^a)的多项式乘起来即可. 考虑优化,取一下ln,转化为加法,然后exp回去就好了.