题目

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. leecode第五十九题(螺旋矩阵 II)

    class Solution { public: vector<vector<int>> generateMatrix(int n) { )//特殊情况 { vector< ...

  2. vue中使用vw适配移动端

    推荐看看大漠老师的文章,非常的有收获 如何在Vue项目中使用vw实现移动端适配 1.首先在项目中安装依赖 npm i postcss-aspect-ratio-mini postcss-px-to-v ...

  3. 类似于placehoder效果的图标展示

    在做app开发的时候往往会有那个注册登录啊,什么的页面,里面就会包含这那种类似于placeholder的效果的图标,当时我也是和ios和安卓混合开发一款app里面的页面全是我写,最开始就是登陆啊,注册 ...

  4. Spring学习笔记(入门)

    1.基本看了一下,spring就是利用这个框架帮助我们实例化对象的工具.首先我们需要引入jar包,pom.xml如下: <project xmlns="http://maven.apa ...

  5. stm32cube使用

    1.使用stm32cube生成CAN代码注意事项: a.需要手动配置CAN过滤器 { CAN_FilterConfTypeDef sFilterConfig; uint32_t filterID = ...

  6. python3 语法小结

    (1) 关键字 # -*- coding: utf-8 -*- #!/usr/bin/python3 """ 1.关键字(保留字) ['False', 'None', ' ...

  7. 广播小案例-监听系统网络状态 --Android开发

    本例通过广播实现简单的监听系统网络状态改变的小案例. 1.案例效果演示 当手机连网后,系统提示“已连接网络”, 当手机断网后,系统提示“当前网络不可用”. 2.案例实现 在主活动中动态注册广播,然后写 ...

  8. FreeBSD之基本配置

    1. 设置IP地址.网关ee /etc/rc.conf ifconfig_em0="inet 192.168.21.173 netmask 255.255.255.0"   #设置 ...

  9. android -------- 解决NDK开发中的 Method 'NewStringUTF' could not be resolved

    创建NDK项目时, .cpp文件中出现错误, Method 'NewStringUTF' could not be resolved 如图: 网上看了很多解决方式 项目右键->属性->c/ ...

  10. css 水平垂直居中显示(定高不定高定宽不定宽)

    position 元素已知宽度 <!DOCTYPE html><html lang="en"><head> <meta charset=& ...