A set of contours is represented on a two dimensional grid as illustrated in the sample below. The contours are made of any printable character different than space and ‘’ (underscore). In the sample this character is ‘X’. All the other points of the grid are represented by spaces and marking characters.
    A grid zone is defined as the set of points enclosed within a closed contour such that any two zone points can be connected by a path which does not cross any contour and whose segments run vertically or horizontally. A zone is marked if it contains identical characters, called marking characters, different than space and the character used to draw the grid contours. No zone can contain different marking characters. However, observe that while all the contours are drawn with the same character, the markings of different zones can be different. A zone is unmarked if it contains only spaces. Any grid zone can be either marked or unmarked and the marking characters can appear inside grid zones only.
    Write a program to fill all the marked zones on each grid read from the input file. A marked zone is filled with its marking character, as shown in the sample.
Input
On input, each grid is terminated by a separation line full of underscores ‘
’. There are at most 32 lines and at most 80 characters in a line for each grid. The lines can be of different length.
Output
The standard output file contains the painted grids. Each grid is output in the same format it is read from the input file, including the separation line, blank lines and possible leading or trailing spaces.
Sample Input

XXXXXXXXXXXXXXXXXXXX
X                 X                          X
X    #    #    XXXXXXXX     / X
X                 X                         X
XXXXXXXXXXXXXXXXXXXX
_____________________________
XXXXXXXXXXXX XXXXXX
X # XXX XXX X X
X XX X X X X
X X X XXXXXXX XXXXXXX
X XX X
X X XXXX XXXXXXXX
XX XXXX X X / X
X X X / X
XXXXXXXXXXXXX XXXXXXXX
_____________________________

Sample Output

XXXXXXXXXXXXXXXXXXXX
X######X///X
X######XXXXXXXXX
X#############XX
XXXXXXXXXXXXXXXXXXXX
_____________________________
XXXXXXXXXXXX XXXXXX
X###########XXX XXX X X
X##XX#########X X X X
X##X X##XXXXXXX XXXXXXX
X###XX###X
X#######X XXXX XXXXXXXX
XX#####XXXX##X X//X
X###########X X//X
XXXXXXXXXXXXX XXXXXXXX
_____________________________

问题链接:UVA785 LA5281 Grid Colouring
问题简述:(略)
问题分析:填充问题,用DFS来实现,需要注意边界的处理。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA785 LA5281 Grid Colouring */#include <bits/stdc++.h>using namespace std;const int R = 32, C = 80 + 1;
char m[R][C];
int r, vis[R][C];void dfs(int row, int col, char c)
{if(row < 0 || row >= r || col < 0) return;if (vis[row][col] || m[row][col] == 'X' || m[row][col] == '\0') return;m[row][col] = c;vis[row][col] = 1;dfs(row - 1, col, c);dfs(row + 1, col, c);dfs(row, col - 1, c);dfs(row, col + 1, c);
}int main()
{r = 0;while (gets(m[r])) {while (m[r][0] != '_')gets(m[++r]);memset(vis, 0, sizeof vis);for (int i = 0; i < r; i++)for (int j = 0; m[i][j]; j++)if (m[i][j] != ' ' && m[i][j] != 'X' && vis[i][j] == 0)dfs(i, j, m[i][j]);for (int i = 0; i <= r; i++)puts(m[i]);r = 0;}return 0;
}

UVA785 LA5281 Grid Colouring【DFS】相关推荐

  1. NUC1158 Lake Counting【DFS】

    Lake Counting 时间限制: 1000ms 内存限制: 65536KB 通过次数: 1总提交次数: 1 问题描述 Due to recent rains, water has pooled ...

  2. Bailian2815 城堡问题【DFS】

    2815:城堡问题 总时间限制: 1000ms 内存限制: 65536kB 描述 1 2 3 4 5 6 7 ############################# 1 # | # | # | | ...

  3. Bailian2816 红与黑【DFS】

    2816:红与黑 总时间限制: 1000ms 内存限制: 65536kB 描述 有一间长方形的房子,地上铺了红色.黑色两种颜色的正方形瓷砖.你站在其中一块黑色的瓷砖上,只能向相邻的黑色瓷砖移动.请写一 ...

  4. NUC1399 Sum It Up【DFS】

    Sum It Up 时间限制: 1000ms 内存限制: 65535KB 通过次数: 1总提交次数: 1 问题描述 Given a specified total t and a list of n ...

  5. [kuangbin]专题三 Dancing Links Squiggly Sudoku HDU - 4069【DFS】【精确覆盖】

    [题目描述] Today we play a squiggly sudoku, The objective is to fill a 9*9 grid with digits so that each ...

  6. NUC1333 Knight Moves【DFS】

    Knight Moves 时间限制: 1000ms 内存限制: 65535KB 问题描述 A friend of you is doing research on the Traveling Knig ...

  7. HDU1181 变形课【DFS】(废除)

    新题解参见:HDU1181 变形课[DFS+关系闭包+bitset] 变形课 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 13107 ...

  8. 【DFS】巧妙取量的倒油问题

    题目描述 [题目描述]  有三个容器,容量分别为 a,b,c(a> b > c ),一开始a装满油,现在问是否只靠abc三个容器量出k升油.如果能就输出"yes",并且 ...

  9. 【DFS】不撞南墙不回头—深度优先搜索算法[Deep First Search]

    今天上午听到,那个非常6+1的李咏先生因癌症去世 DFS算法的基本模型 深度下,不撞南墙不回头,就是一直往后找,知道没有路了,向后返回. 想起一首民谣,<可能否>--木小雅 https:/ ...

最新文章

  1. ASP.NET: 简要分析Table类的使用
  2. 95%PyTorch库都会中招的bug!特斯拉AI总监都没能幸免
  3. 数据结构-王道-树和二叉树
  4. java 抽象类,接口,object类详解
  5. 动态规划 53:Maximum Subarray,152:Maximum Subarray,266. Palindrome Permutation 回文全排列...
  6. 想获得腾讯发行机会?来“腾讯GAD•游戏创新大赛”
  7. SpringMVC的运行原理
  8. IT 架构之学习教材 -WSSRA
  9. Python 基础---列表
  10. websocket php apache,PHP第一篇:PHP WebSocket实现前后端数据交互,亲测可用(windows+ apache2.4 +php5.6 )...
  11. kali免杀工具Veil Evasion
  12. 基于PHP+Zend Studio 13 + MYSQL+饭店预订管理系统
  13. IDEA鼠标光标变黑块问题解决
  14. 数值分析:复化梯形公式与复化Simpson公式
  15. php 模板对象,php面向对象--PHP模板 ppt
  16. MiniGUI中的几个画线函数
  17. 分享谷歌浏览器的一个插件-OneTab,非常赞
  18. 为什么都推崇测试先行?论软件测试先行的12个好处
  19. carto_grapher快速安装避坑指南
  20. 图像识别 - C++读取bmp位图入门

热门文章

  1. 2019-07-03
  2. pdsh命令控制多台树莓派超爽
  3. javaweb不同用户登录不同页面的页面_Java Web轻松学36 - 第二个Servlet应用租房网(1)...
  4. linux 内核文件操作,Linux 内核文件操作
  5. linux中.开头的变量,linux中的变量
  6. Scala初步学习(三)
  7. 详解:Hive的存储格式与对比
  8. jmeter分布式性能测试
  9. linux 调试 js 代码,使用node-inspector调试NodeJS代码
  10. python爱心代码_母亲节快到了,用Python给老妈写个祝福小程序吧~