HDU 1312 Red and Black(最简单也是最经典的搜索)
传送门:
http://acm.hdu.edu.cn/showproblem.php?pid=1312
Red and Black
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25397 Accepted Submission(s): 15306
Write a program to count the number of black tiles which he can reach by repeating the moves described above.
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)
....#.
.....#
......
......
......
......
......
#@...#
.#..#.
11 9
.#.........
.#.#######.
.#.#.....#.
.#.#.###.#.
.#.#..@#.#.
.#.#####.#.
.#.......#.
.#########.
...........
11 6
..#..#..#..
..#..#..#..
..#..#..###
..#..#..#@.
..#..#..#..
..#..#..#..
7 7
..#.#..
..#.#..
###.###
...@...
###.###
..#.#..
..#.#..
0 0
59
6
13
#include<bits/stdc++.h>
using namespace std;
#define max_v 25
char G[max_v][max_v];
int n,m;
int sx,sy;
int step;
int dir[][]={,,,,,-,-,};
void dfs(int x,int y)
{
int xx,yy;
for(int i=;i<;i++)
{
xx=x+dir[i][];
yy=y+dir[i][];
if(xx>=&&xx<n&&yy>=&&yy<m&&G[xx][yy]!='#')
{
step++;
G[xx][yy]='#';
dfs(xx,yy);
}
}
}
int main()
{
while(~scanf("%d %d",&m,&n))
{
if(n==&&m==)
break;
getchar();
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
cin>>G[i][j];
if(G[i][j]=='@')
{
sx=i;
sy=j;
}
}
}
step=;
G[sx][sy]='#';
dfs(sx,sy);
cout<<step<<endl;
}
return ;
}
HDU 1312 Red and Black(最简单也是最经典的搜索)的更多相关文章
- 题解报告:hdu 1312 Red and Black(简单dfs)
Problem Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...
- HDU 1312 Red and Black --- 入门搜索 BFS解法
HDU 1312 题目大意: 一个地图里面有三种元素,分别为"@",".","#",其中@为人的起始位置,"#"可以想象 ...
- 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 (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(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(bfs)
Red and Black Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descr ...
- HDU 1312 Red and Black(经典DFS)
嗯... 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 一道很经典的dfs,设置上下左右四个方向,读入时记下起点,然后跑dfs即可...最后答 ...
随机推荐
- 环境搭建:JDK--SSH--VIM--Hadoop--SybaseIQ
放假闲来无事,就自己搭建了一套环境,包含: 工具:ssh,vim 环境:Jdk,Hadoop 在此记录,下次使用 1.工具类 ssh和vim两个常用的工具就是两条命令: vim命令:sudo a ...
- 深入理解JavaScript系列(29):设计模式之装饰者模式
介绍 装饰者提供比继承更有弹性的替代方案. 装饰者用用于包装同接口的对象,不仅允许你向方法添加行为,而且还可以将方法设置成原始对象调用(例如装饰者的构造函数). 装饰者用于通过重载方法的形式添加新功能 ...
- .net 金额中文大写 日期转中文
金额中文大写 #region 中文大写 /// <summary> /// 返回中文数字 ,如壹佰元整 /// </summary> /// <param name=&q ...
- linux安装lua_nginx_module模块
ngx_lua_module 是一个nginx http模块,它把 lua 解析器内嵌到 nginx,用来解析并执行lua 语言编写的网页后台脚本,可以用来实现灰度发布.另外淘宝的OpenResty也 ...
- main方法击破
什么是main方法? 是类中的一段代码,可以让程序独立运行. public class HelloWord{ public static void main(String[] args) { for ...
- C# 读写xml、excel、word、ppt、access
C# 读写xml.excel.word.access 这里只是起个头,不做深入展开,方便以后用到参考 读写xml,主要使用.net 的xml下的document using System;using ...
- cf1064D. Labyrinth(01BFS)
题意 题目链接 给出一个\(n \times m\)的网格,给出起始点,要求向左走不超过\(L\)步,向右走不超过\(R\)步,求出能遍历到哪些点 Sol 一个很直观的想法,BFS的时候状态里记录下还 ...
- sharepoint2007就地升级2010系列(一)2007概览
大家可能熟悉了sharepoint2010,熟悉了sharepoint2013,做了N多个项目,但是有没有做过从sharepoint2007升级或者迁移到sharepoint2010的项目呢?我们做实 ...
- bit byte 字 字节 关系 简列
字 word 字节 byte 位 bit 字长是指字的长度 1字=2字节(1 word = 2 byte = 16bit) 1字节=8比特(1 byte = 8bit) 1比特=1位 一个字的字长为1 ...
- spring框架入门day02
0. 绪论 在第二天的学习中的学习JdbcTemplate之前,想要下载最新版本的mysql server8.0.11 结果在将所有的东西配置好后,发现报错, · Establishing SSL c ...