hdoj1312Red and Black(递归)
来源:互联网 发布:apk网络电视bbs 编辑:程序博客网 时间:2024/06/06 12:45
Red and Black
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13136 Accepted Submission(s): 8136
Problem Description
There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles.
Write a program to count the number of black tiles which he can reach by repeating the moves described above.
Write a program to count the number of black tiles which he can reach by repeating the moves described above.
Input
The input consists of multiple data sets. A data set starts with a line containing two positive integers W and H; W and H are the numbers of tiles in the x- and y- directions, respectively. W and H are not more than 20.
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)
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)
Output
For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself).
Sample Input
6 9....#......#..............................#@...#.#..#.11 9.#..........#.#######..#.#.....#..#.#.###.#..#.#..@#.#..#.#####.#..#.......#..#########............11 6..#..#..#....#..#..#....#..#..###..#..#..#@...#..#..#....#..#..#..7 7..#.#....#.#..###.###...@...###.###..#.#....#.#..0 0
Sample Output
4559613
题意:某人在@处为起点(也包括@点)#为墙,点(.)为通路,问最多能走多远统计能走几个点(加上@这个点)
#include<stdio.h>char a[50][50];int n,m,count;void fun(int x,int y){if(a[x][y]=='#')//看看是不是墙 return ;if(x>m||y>n||x<1||y<1)//在范围内 return ;count++;a[x][y]='#';//已经查到得这个点就要变成墙,否则的话 就变成无限的查找了 fun(x-1,y);//查上下左右四个点 fun(x+1,y);fun(x,y+1);fun(x,y-1);}int main(){int i,j,b,c;while(~scanf("%d %d",&n,&m))//n行m列 {count=0;if(n==0||m==0)return 0;for(i=1;i<=m;i++){getchar();for(j=1;j<=n;j++){scanf("%c",&a[i][j]);//找出@点在几行几列 if(a[i][j]=='@')b=i,c=j;}}fun(b,c);//查一下在这个点周围还有几个点 printf("%d\n",count);}return 0;}
0 0
- hdoj1312Red and Black(递归)
- hdoj1312Red and Black
- hdoj1312Red and Black
- hdu1312 red and black 【递归】
- HD1312 Red and Black【递归】
- A - Red and Black(3.2.1)(小递归)
- poj 1979 Red and Black 递归实现
- HDU 1312:Red and Black【递归】
- HDU 1312 Red and Black【递归】
- 递归回溯法实战(一)——(Red and Black)红黑砖迷阵(POJ1979)
- Red and Black(bfs)
- POJ1979(Red and Black)
- Red and Black(搜索)
- Red and Black(DFS)
- Red and Black(DFS)
- hdu1312(Red and Black)
- Red and Black (BFS)
- hdu1312Red and Black (dfs)
- XTU 1238 线段树
- poj 3370
- SAP NCO中间件 server模式测试
- 登录界面验证码的生成
- Dreamweaver工具使用
- hdoj1312Red and Black(递归)
- ubuntu下忘记root 密码的解决方法
- java事务相关异常的排查方法
- 如何用ThinkPHP的Save方法,保存未被修改的数值
- CF 26A-Almost prime
- QHeaderView的visualIndex和logicalIndex
- 25.UITouch
- POJ 1062 昂贵的聘礼
- RHEL6.4在RHCS环境下,重新划分LVM时遇到无法创建LV的问题