POJ 1979 题解
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 31722 | Accepted: 17298 |
Description
Write a program to count the number of black tiles which he can reach by repeating the moves described above.
Input
There are H more lines in the data set, each of which includes W characters. Each character represents the color of a tile as follows.
'.' - a black tile
'#' - a red tile
'@' - a man on a black tile(appears exactly once in a data set)
The end of the input is indicated by a line consisting of two zeros.
Output
Sample Input
- 6 9
- ....#.
- .....#
- ......
- ......
- ......
- ......
- ......
- #@...#
- .#..#.
- 11 9
- .#.........
- .#.#######.
- .#.#.....#.
- .#.#.###.#.
- .#.#..@#.#.
- .#.#####.#.
- .#.......#.
- .#########.
- ...........
- 11 6
- ..#..#..#..
- ..#..#..#..
- ..#..#..###
- ..#..#..#@.
- ..#..#..#..
- ..#..#..#..
- 7 7
- ..#.#..
- ..#.#..
- ###.###
- ...@...
- ###.###
- ..#.#..
- ..#.#..
- 0 0
Sample Output
- 45
- 59
- 6
- 13
Source
- #include "cstdio"
- #include "cstring"
- #include "cmath"
- #include "iostream"
- #include "string"
- using namespace std ;
- const int maxN = ;
- const int dx[ ] = { , , , - } ;
- const int dy[ ] = { , , - , } ;
- char mp[ maxN ][ maxN ] ;
- int N , M ;
- void DFS ( const int xi , const int yi ) {
- if ( !mp[ xi ][ yi ] )return ;
- mp[ xi ][ yi ] = '%' ;
- for ( int i= ; i< ; ++i ) {
- int xx = xi + dx[ i ] ;
- int yy = yi + dy[ i ] ;
- if ( xx > && xx <= M && yy > && yy <= N && mp[ xx ][ yy ] == '.' )
- DFS( xx , yy ) ;
- }
- }
- int sumerize ( const int n , const int m ) {
- int ret ( ) ;
- for ( int i= ; i<=n ; ++i ) {
- for ( int j= ; j<=m ; ++j ) {
- if ( mp[ i ][ j ] == '%' ) ++ret ;
- }
- }
- return ret ;
- }
- int main ( ) {
- int start_x , start_y ;
- while ( scanf ( "%d%d\n" , &N , &M ) == && N && M ) {
- for ( int i= ; i<=M ; ++i ) {
- scanf ( "%s" , mp[ i ] + ) ;
- }
- for ( int i= ; i<=M ; ++i ) {
- for ( int j= ; j<=N+ ; ++j ) {
- if ( mp[ i ][ j ] == '@' ) {
- mp[ i ][ j ] = '.' ;
- start_x = i ;
- start_y = j ;
- goto Loop ;
- }
- }
- }
- Loop :
- DFS ( start_x , start_y ) ;
- printf ( "%d\n" , sumerize ( M , N ) ) ;
- memset ( mp , , sizeof ( mp ) ) ;
- }
- return ;
- }
2016-10-21 16:28:48
POJ 1979 题解的更多相关文章
- POJ 1979 Red and Black (红与黑)
POJ 1979 Red and Black (红与黑) Time Limit: 1000MS Memory Limit: 30000K Description 题目描述 There is a ...
- poj 1979 Red and Black 题解《挑战程序设计竞赛》
地址 http://poj.org/problem?id=1979 Description There is a rectangular room, covered with square tiles ...
- POJ 1979 Red and Black dfs 难度:0
http://poj.org/problem?id=1979 #include <cstdio> #include <cstring> using namespace std; ...
- POJ 1979 dfs和bfs两种解法
fengyun@fengyun-server:~/learn/acm/poj$ cat 1979.cpp #include<cstdio> #include<iostream&g ...
- OpenJudge/Poj 1979 Red and Black / OpenJudge 2816 红与黑
1.链接地址: http://bailian.openjudge.cn/practice/1979 http://poj.org/problem?id=1979 2.题目: 总时间限制: 1000ms ...
- poj 1979 Red and Black(dfs)
题目链接:http://poj.org/problem?id=1979 思路分析:使用DFS解决,与迷宫问题相似:迷宫由于搜索方向只往左或右一个方向,往上或下一个方向,不会出现重复搜索: 在该问题中往 ...
- POJ 1979 DFS
题目链接:http://poj.org/problem?id=1979 #include<cstring> #include<iostream> using namespace ...
- POJ 1979 红与黑
题目地址: http://poj.org/problem?id=1979 或者 https://vjudge.net/problem/OpenJ_Bailian-2816 Red and Blac ...
- POJ 1979 Red and Black (zoj 2165) DFS
传送门: poj:http://poj.org/problem?id=1979 zoj:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problem ...
随机推荐
- Lisp永远成不了编程主流语言
Lisp语言是第二古老的高级编程语言.许多的黑客和开发者对Lisp推崇备至,Paul Graham甚至说"编程语言现在的发展,不过刚刚赶上1958年Lisp语言的水平". ...
- 对前台传回的list进行分割,并放在sql语句的in中
前端数据集传回数据 var matDeptHisMonthPlanStore = Ext.data.StoreManager.lookup('matDeptHisMonthPlanStore'); m ...
- 项目vue2.0仿外卖APP(二)
vue-cli开启vue.js项目 github地址:https://github.com/vuejs/vue-cli Vue.js开发利器vue-cli,是vue的脚手架工具. 在工地上,脚手架是工 ...
- react+redux官方实例TODO从最简单的入门(4)-- 改
上一篇文章实现了<删>这个功能,那么我们继续添加下一功能--<改> 这个修改的功能是通过双击每个子选项实现 第一步:按规矩来,添加一个状态声明 第二步:action中约定我们要 ...
- PPM图片格式及其C读写代码
PPM图像格式介绍 PPM图像格式是由Jef Poskanzer 大叔,在我出生那一年,也就是1991年所创造的,碰巧的是PPM也是天蝎座. PPM(Portable Pixmap Format)还有 ...
- kali python pip3 的安装和卸载
今天很高兴安装完成调整了kali 然后看见kali已经帮助我安装了python2.7和python3.5可把我开心坏了,可是2.7有pip,而且包很全,但2.7与3.0切换使用我的就尴尬了 最后在su ...
- asp.net 文件下载(txt,rar,pdf,word,excel,ppt)
aspx 文件下载说起来一点都不难,但是在做的过程中还是遇到了一些小小的问题,就是因为这些小小的问题,导致解决起来实在是太难了,其中一个就是Response.End();导致下载文件出现线程终止的情况 ...
- 浅谈HTTP中Get与Post的区别
引用自:http://www.cnblogs.com/hyddd/archive/2009/03/31/1426026.html Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET ...
- js方法入参或局部变量和全局变量重名,用来赋值全局变量会失败
今天遇到个bug,最后终于知道原因了,js方法入参和全局变量重名,用入参赋值全局变量失败,就是说方法入参不能和全局变量重名. 现在下面的例子也说明,局部变量和全局变量不可以同名不光是入参,只要同名赋值 ...
- linux系统的初化始配置
一.网络的初始化 1.ip地址的修改(临时生效) 使用ifconfig命令 ifconfig 网卡名 ip地址 子网掩码 [root@localhost /]# ifconfig eno1677773 ...