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 ...
随机推荐
- [Kubernetes]PV,PVC,StorageClass之间的关系详解
在Kubernetes中,容器化一个应用比较麻烦的地方莫过于对其"状态"的管理,而最常见的"状态",莫过于存储状态. 在[Kubernetes]深入理解Stat ...
- MailKit系列之转发电子邮件
原文:http://www.it1352.com/429181.html 问题 我尝试通过MailKit访问一个IMAP账号,我设法下载邮件(作为的MimeMessage),并在某些时候我需要转发给其 ...
- SpringJUnit4ClassRunner (单元测试)
1.在Maven的pom.xml中加入 <dependency> <groupId>junit</groupId> <artifactId>junit& ...
- 2-4、配置Filebeat使用logstash
配置filebeat使用logstash 重要:要将事件发送到Logstash,还需要创建一个Logstash配置管道,该管道监听传入的Beats连接并将收到的事件编入索引到Elasticsearch ...
- linux统配符
linux通配符注意:linux的通配符和三剑客的表达式是不一样的,因为,代表的意义是有较大区别的.通配符一般用户命令行bash环境,而linux正则表达式用于grep,sed,awk场景. * ...
- nginx代理 (带着请求头)
当你获得云服务器之后, 你有这样一个需求:当你要访问一个url的时候,这个URL只能在人家的云服务器上访问(比如百度),所以你要买百度的BCC,你可能在想在BCC起服务,那样有点麻烦,直接使用ngin ...
- ios访问web页面<div>点击事件不起效果,以及alert()显示url的解决办法
ios访问web页面<div>点击不起效果,在其div上添加style=”cursor:pointer:“ jquery web页面动态append()事件调用方法:$(document) ...
- Java生日计算年龄工具
package com.web.backend.util; import java.util.Calendar;import java.util.Date; /** * @Author: SongZS ...
- mysql函数取出单个字段重新组成一维数组
array_column():
- swagger.net 使用nginx 代理时出现端口号导致出错
1:当我们通过nginx代理访问时,由于nginx配置了映射到的一个站点为端口为127.0.0.1:6201,导致访问swagger接口时出现增加端口号,如下截图,这样就导致整个swagger无法使用 ...