Red and Black---POJ - 1979
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
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m;
int ans=;
int vis[][];
char title[][];
int fx[]={-,,,},fy[]={,,,-}; void dfs(int x,int y){
ans++;
vis[x][y]=;
for(int i=; i<; i++ ){
int nx=x+fx[i];
int ny=y+fy[i];
if(nx>=&&nx<n&&ny>=&&ny<m&&title[nx][ny]=='.'&&!vis[nx][ny]){
dfs(nx,ny);
}
}
} int main(){
while(~scanf("%d%d",&m,&n)&&n&&m){
// getchar();
ans=;
memset(vis,,sizeof(vis));
for( int i=; i<n; i++ ){
cin>>title[i];
}
for( int i=; i<n; i++ ){
for(int j=; j<m; j++ ){
if(title[i][j]=='@'&&!vis[i][j]){
dfs(i,j);
break;
}
}
}
printf("%d\n",ans);
} return ;
}
Red and Black---POJ - 1979的更多相关文章
- Red and Black(poj 1979 bfs)
Red and Black Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 27891 Accepted: 15142 D ...
- DFS:Red and Black(POJ 1979)
红与黑 题目大意:一个人在一个矩形的房子里,可以走黑色区域,不可以走红色区域,从某一个点出发,他最多能走到多少个房间? 不多说,DFS深搜即可,水题 注意一下不要把行和列搞错就好了,我就是那样弄错过一 ...
- POJ 1979 Red and Black (红与黑)
POJ 1979 Red and Black (红与黑) Time Limit: 1000MS Memory Limit: 30000K Description 题目描述 There is a ...
- 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 题解《挑战程序设计竞赛》
地址 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 Red and Black(dfs)
题目链接:http://poj.org/problem?id=1979 思路分析:使用DFS解决,与迷宫问题相似:迷宫由于搜索方向只往左或右一个方向,往上或下一个方向,不会出现重复搜索: 在该问题中往 ...
- 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 ...
- HDOJ 1312 (POJ 1979) Red and Black
Problem Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...
- poj 1979 Red and Black(dfs水题)
Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...
随机推荐
- IntelliJ IDEA安装ideaIU-2019.1
- UGUI中粒子特效与UI的遮挡问题
问题背景: 在做主线任务时发现完成任务后的特效显示穿透上面的UI层,不美观,策划不乐意了,抓紧解决下 解决思路: 首先讲下影响渲染顺序的因素: 能够影响渲染顺序的因素有:1.Camera Depth ...
- 将Go的main包拆分为多个文件
将Go的main包拆分为多个文件的写法和普通包是完全一致的,其使用规则也相同.如编写main包结构如下: main |----main.go |----show.go 在main.go中编写了main ...
- 使用Jenkins时,如果GIT_COMMIT无变化,跳过构建
使用Jenkins时,如果GIT_COMMIT无变化,跳过构建 使用插件: conditional-buildstep A buildstep wrapping any number of ot ...
- Liunx系统下的进程与线程
1. 进程.线程的概念 a. 进程是操作系统进行资源分配的单位. b. 线程(Thread)是程序中独立的指令流,是CPU调度和分派的基本单位. c. 多进程是指同时运行多种 ...
- C# 实现 Snowflake算法生成唯一性Id
参考地址:https://blog.csdn.net/w200221626/article/details/52064976 /// <summary> /// 动态生产有规律的ID // ...
- Codeforces 677E Vanya and Balloons
Vanya and Balloons 枚举中心去更新答案, 数字过大用log去比较, 斜着的旋转一下坐标, 然后我旋出来好多bug.... #include<bits/stdc++.h> ...
- angular之表达式
1.作用:使用表达式把数据绑定到HTML. 2.语法:表达式写在双打括号内:{{expression}} 3.比较:表达式作用类似于ng-bind指令:建议更多的使用指令. 4.AngularJS表达 ...
- Array库
/** * 查找元素在数组中出现的所有位置 * @param {要查找的数组} array * @param {要查找的元素} ele * @param {回调函数} callback */ func ...
- 基于Emgucv,C#的图片旋转方式
/// <summary> /// 图片旋转 --百度 旋转仿射 /// </summary> /// <param name="modelImage" ...