DFS-HDU 1312 -Red and Black
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
Description
only on black tiles.
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)
Output
Sample Input
6 9
....#.
.....#
......
......
......
......
......
#@...#
.#..#.
11 9
.#.........
.#.#######.
.#.#.....#.
.#.#.###.#.
.#.#..@#.#.
.#.#####.#.
.#.......#.
.#########.
...........
11 6
..#..#..#..
..#..#..#..
..#..#..###
..#..#..#@.
..#..#..#..
..#..#..#..
7 7
..#.#..
..#.#..
###.###
...@...
###.###
..#.#..
..#.#..
0 0
Sample Output
45
59
6
13
这题已经不想在吐槽什么了,n,m 和正常的出相反 害我一些细节错 一直WA 还说到底还是自己太弱了
#include<iostream>
using namespace std; #include<string.h>
#define max 25
char map[max][max];int mmin;
long n,m,visited[max][max];
long directions[4][2]={{0,-1},{0,1},{1,0},{-1,0}}; void DFS(int x,int y)
{
int i,mx,my;
for(i=0;i<4;i++)
{
mx=x+directions[i][0];
my=y+directions[i][1];
if(mx>=0&&mx<m&&my>=0&&my<n)
{
if(!visited[mx][my]&&map[mx][my]=='.')
{
visited[mx][my]=1;
mmin++;
DFS(mx,my);
}
}
}
}
int main()
{ int i,j,a,b;
while(cin>>n>>m)
{
if(n==0&&m==0)break;
memset(visited,0,sizeof(visited)); for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>map[i][j];
if(map[i][j]=='@')
{
a=i,b=j;
}
}
}
mmin=1;
visited[a][b]=1;
DFS(a,b);
cout<<mmin<<endl;
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
DFS-HDU 1312 -Red and Black的更多相关文章
- HDU 1312 Red and Black --- 入门搜索 DFS解法
HDU 1312 题目大意: 一个地图里面有三种元素,分别为"@",".","#",其中@为人的起始位置,"#"可以想象 ...
- HDU 1312:Red and Black(DFS搜索)
HDU 1312:Red and Black Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
- HDU 1312 Red and Black --- 入门搜索 BFS解法
HDU 1312 题目大意: 一个地图里面有三种元素,分别为"@",".","#",其中@为人的起始位置,"#"可以想象 ...
- HDU 1312 Red and Black (dfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 Red and Black Time Limit: 2000/1000 MS (Java/Oth ...
- HDU 1312 Red and Black(bfs,dfs均可,个人倾向bfs)
题目代号:HDU 1312 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 Red and Black Time Limit: 2000/100 ...
- HDU 1312 Red and Black(最简单也是最经典的搜索)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1312 Red and Black Time Limit: 2000/1000 MS (Java/Oth ...
- HDU 1312 Red and Black(DFS,板子题,详解,零基础教你代码实现DFS)
Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU 1312 Red and Black(经典DFS)
嗯... 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 一道很经典的dfs,设置上下左右四个方向,读入时记下起点,然后跑dfs即可...最后答 ...
- HDU 1312 Red and Black (DFS & BFS)
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 题目大意:有一间矩形房屋,地上铺了红.黑两种颜色的方形瓷砖.你站在其中一块黑色的瓷砖上,只能向相 ...
- hdu 1312:Red and Black(DFS搜索,入门题)
Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
随机推荐
- PeopleSoft Object Types Definitions
PeopleSoft stores object definitions types such as Record, Field and SQL definitions as numbers in ...
- VS2010 /VC/bin/rcdll.dll 无法找到资源编译器
把C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin 目录下的rcdll.dll拷贝到 C:\Program Files(x86)\Micr ...
- [leetcode]_Reverse Integer
经历了三道树的题后,完全崩溃中,急需一道非树图的题来挽救信心. 题目:反转数字.input : 123 , output : 321. 思路:直接,没什么好说的. 自己代码:很龊,有大量的冗余信息,还 ...
- js 实现栈
function Stack() { this.dataStore = []; this.top = 0; this.push=push; this.pop=pop; this.peek=peek; ...
- A-Frame_简单介绍
VR框架A-Frame: https://aframe.io 版本: 0.2.0 30/6/2016 A-Frame 是一个能够实现在web网页上实现3D和VR体验的开源框架,它是由 MozVR ...
- postgresql 入门(含java、scala连接代码)
1.下载安装包 官网:http://www.postgresql.org/download/ 按自己需求,下载安装包, 我下载的windows版32位的.http://get.enterprisedb ...
- 百度分享如何自定义分享url和内容?
百度分享默认分享的是当前页的url,但也可以在同一个页面中分享多个不同的url,仅需进行如下简单的配置. 默认的代码如下: <div id="bdshare" class=& ...
- autolayout 总结
hasAmbiguousLayoutexerciseAmbiguityInLayout_autolayoutTracerecursiveDescription 第一步:更新约束,可以被认为是一个“计量 ...
- 使用eclipse开发
Eclipse下载地址:http://www.eclipse.org/ 下载后进行解压缩,点击eclipse.exe即可使用eclipse workspace:工作区 Project:项目 ...
- dubbox使用
1.命令行下 git clone https://github.com/dangdangdotcom/dubbox 2.mvn install -Dmaven.test.skip=true 跳过测试编 ...