UVa 785 - Grid Colouring
来源:互联网 发布:淘宝基金不见了 编辑:程序博客网 时间:2024/05/21 21:50
题目:给你一个二维的图片,上面有很多个独立的区域被用'X'的边界分隔开,有一些子区域中有填充的字符,
如果发现填充字符,就把这个子区域用这种字符填满(不会出现一个子区域中存在多余一种填充字符)。
分析:图论、搜索,floodfill。如果发现填充字符,直接利用递归填充上下左右方向的格子即可。
说明:本周刷的题好少╮(╯▽╰)╭。
#include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <cmath>using namespace std;char maps[31][81];int smap[31][81];void dfs(int x, int y, int n, char c){if (smap[x][y] || maps[x][y] == 'X') return;maps[x][y] = c;smap[x][y] = 1;dfs(x-1, y, n, c);dfs(x+1, y, n, c);dfs(x, y-1, n, c);dfs(x, y+1, n, c);}int main(){int count = 0;while (gets(maps[count])) {while (maps[count][0] != '_') gets(maps[++ count]);memset(smap, 0, sizeof(smap));for (int i = 0; i < count; ++ i)for (int j = 0; maps[i][j]; ++ j)if (maps[i][j] != ' ' && maps[i][j] != 'X')dfs(i, j, count, maps[i][j]);for (int i = 0; i <= count; ++ i)puts(maps[i]);count = 0;} return 0;}
0 0
- UVa 785 - Grid Colouring
- UVA 11553 - Grid Game
- UVA - 12036 Stable Grid
- UVA 11916 Emoogle Grid 数论
- UVA 11916 - Emoogle Grid(数论)
- uva 10671 - Grid Speed(dp)
- UVA 12382 Grid of Lamps
- URAL 1080 Map Colouring [简单DFS]
- uva 10913 Walking on a Grid
- UVA 10913 Walking on a Grid
- Uva 10913 - Walking on a Grid
- UVa 10913 - Walking on a Grid dp
- UVA - 10913 Walking on a Grid
- UVa:10913 Walking on a Grid
- UVa 12036 Stable Grid (想法题)
- UVA 11916 Emoogle Grid(离散对数)
- uva 10913Walking on a Grid
- uva 11916 - Emoogle Grid(大步小步算法)
- pinyin4j原理说明
- [Practical.Vim(2012.9)].Drew.Neil.Tip52 学习摘要
- poj2409Let it Bead
- 闲聊
- Html语法大全
- UVa 785 - Grid Colouring
- iOS开发笔记6--KVC,KVO,通知
- 安卓学习笔记之一
- 全球通史(1)
- 第八周项目一之实现复数类中的运算符重载
- static_cast, dynamic_cast, const_cast
- 第7周项目2-实现复数类中的运算符重载(1、成员函数)
- 课程: Introduction to Programming with MATLAB in coursera
- 机房收费系统--总结