HDU 1312 Red and Black(bfs)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
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
Sample Output
#include<cstdio>
#include<cstring> using namespace std;
int n,m,sx,sy;
char mp[][];
int vis[][];
int dx[]={,,,-};
int dy[]={,-,,};
bool check(int x,int y)
{
return x>=&&x<n&&y>=&&y<m;
}
struct node
{
int x,y;
}St[]; int bfs()//手写的队列,队列的尾端就是到达的点的数量
{
memset(vis,,sizeof vis);
int st=,en=;
vis[St[].x][St[].y]=;
while(st<en)
{
node e=St[st++];
for(int i=;i<;i++)
{
node w=e;
w.x=e.x+dx[i],w.y=e.y+dy[i];
if(check(w.x,w.y)&&vis[w.x][w.y]==&&mp[w.x][w.y]!='#')
{
vis[w.x][w.y]=;
St[en++]=w;
}
}
}
return en;
} int main()
{
while(scanf("%d%d",&m,&n)!=EOF&&(n||m))
{
for(int i=;i<n;i++)
{
scanf("%s",mp[i]);
for(int j=;j<m;j++)
if(mp[i][j]=='@')
St[].x=i,St[].y=j;
}
printf("%d\n",bfs());
}
return ;
}
Red and Black
HDU 1312 Red and Black(bfs)的更多相关文章
- 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)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 Red and Black Time Limit: 2000/1000 MS (Java/Oth ...
- HDU.2612 Find a way (BFS)
HDU.2612 Find a way (BFS) 题意分析 圣诞节要到了,坤神和瑞瑞这对基佬想一起去召唤师大峡谷开开车.百度地图一下,发现周围的召唤师大峡谷还不少,这对基佬纠结着,该去哪一个...坤 ...
- 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(最简单也是最经典的搜索)
传送门: 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)
嗯... 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 一道很经典的dfs,设置上下左右四个方向,读入时记下起点,然后跑dfs即可...最后答 ...
- hdu 1312:Red and Black(DFS搜索,入门题)
Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 题解报告: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 (DFS & BFS)
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 题目大意:有一间矩形房屋,地上铺了红.黑两种颜色的方形瓷砖.你站在其中一块黑色的瓷砖上,只能向相 ...
随机推荐
- [转]如何正确设置nginx中remote_addr和x_forwarded_for参数
做网站时经常会用到remote_addr和x_forwarded_for这两个头信息来获取客户端的IP,然而当有反向代理或者CDN的情况下,这两个值就不够准确了,需要调整一些配置. 什么是remote ...
- haproxy之负载均衡算法
backend blance 算法 动态hash的特点 服务器运行时就可进行权重调整,即只需要重新载入配置文件即可,不需要重新启动haproxy 支持慢速启动,即重新恢复的后端 ...
- robot自动化测试(二)--- template使用
首先贴一下测试结构 测试流程: 1.打开百度主页 2.搜索框输入搜索内容 3.获取浏览器title 4.验证title的正确性 百度搜索业务关键字:采用分层结构:只需输入要搜索的内容:${search ...
- 异常处理与调试5 - 零基础入门学习Delphi54
调试(Debug) 让编程改变世界 Change the world by program [caption id="attachment_2731" align="al ...
- 启动PL/SQL Developer 报字符编码不一致错误,Database character set
错误内容: Database character set (AL32UTF8) and Client character set (ZHS16GBK) are different. Character ...
- web容器 - Jetty
详解web容器 - Jetty与Tomcat孰强孰弱 Jetty 基本架构 Jetty目前的是一个比较被看好的 Servlet 引擎,它的架构比较简单,也是一个可扩展性和非常灵活的应用服务器. 它 ...
- android style="@[package:]style/style_name" ----------styles.xml
android.widget ----XML attribute |____style="@[package:]style/style_name"
- NOI十连测 第五测 T1
#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #inclu ...
- Types of Binary Tree
Complete Binary Tree According to wiki, A complete binary tree is a binary tree in which every level ...
- PHP 表单验证 - 必填字段
-------------------------------------------------------------------------- 本节展示如何制作必填输入字段,并创建需要时所用的错 ...