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 ...
随机推荐
- 由table理解display:table-cell
转载自:https://segmentfault.com/a/1190000007007885 table标签(display:table) 1) table可设置宽高.margin.border.p ...
- MySQL学习(七)
学习子查询 1 查出本网站最新的good_id最大的一条商品(要求取出商品名) mysql> select goos_id,goods_name from goods -> order b ...
- MYSQL常用函数(聚合函数(常用于GROUP BY从句的SELECT查询中))
AVG(col)返回指定列的平均值 COUNT(col)返回指定列中非NULL值的个数 MIN(col)返回指定列的最小值 MAX(col)返回指定列的最大值 SUM(col)返回指定列的所有值之和 ...
- java再次学习
1.maven配置.
- ADO.NET梳理
目录: 简单的介绍下ADO.NET SqlConnection(连接对象) SqlCommand(命令对象) SqlParameter(Sql参数) SqlDataReader(数据流读取器) Sql ...
- TCHART类型
private Steema.TeeChart.Styles.Pie pieSeries1; private Steema.TeeChart.Styles.Pie pieSeries2; privat ...
- every day a practice —— morning(2)
Two years at sea have fostered a close relationship between the two fellow sailors as they cross the ...
- 2018JavaScript状态调查:5个重要的思考( import takeaways) (摘译)
英文原文 (内有视频). 以下是翻译和摘录. 最近JS状态调查结构出来了,如果你关心网页开发,你会关心这些结果. 本文探索5个takeaways并总结这些结论. 1. JavaScript Had ...
- 使用jquery.mobile和WebSQL实现记事本功能
1.记事本列表页 1.1.页面结构与样式: <div data-role="page" id="home"> <div data-role=& ...
- 三种css样式表及其优先级
1.行内样式 body内: <p style="text-indent: 2em;color: red"> 我是行内样式 </p> 2.内部样式表 body ...