//注意边界判断,调了好久

#include <iostream>
#include <queue>
using namespace std;
#define check(x,y)(x<wx&&x>=0&&y<hy&&y>=0) struct node {
int x, y;
};
char room[23][23];
int n, m, wx, hy, num; int dir[4][2] = {
{-1, 0}, {0, -1}, {1, 0}, {0, 1}
}; void bfs(int dx, int dy) {
num = 1; queue<node>q;
node start, next;
start.x = dx;
start.y = dy;
q.push(start);
while (!q.empty()) {
start = q.front();
q.pop();
// cout<<"out"<<start.x<<' '<<start.y<<endl;
for (int i = 0; i < 4; i++) {
next.x = start.x + dir[i][0];
next.y = start.y + dir[i][1];
if (check(next.x, next.y) && room[next.x][next.y] == '.') {
room[next.x][next.y] = '#';
num++;
q.push(next);
} }
}
} int main() {
int x, y, dx, dy;
while (cin >> wx >> hy) {
if (wx == 0 && hy == 0) {
break;
}
for ( y = 0; y < hy; y++) {
for (int x = 0; x < wx; x++) {
cin >> room[x][y];
if (room[x][y] == '@') {
dx = x;
dy = y;
}
}
}
num = 0;
bfs(dx, dy);
cout << num << endl;
}
return 0;
}

HDU 1312 Red and Black 题解的更多相关文章

  1. HDU 1312:Red and Black(DFS搜索)

      HDU 1312:Red and Black Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

  2. HDU 1312 Red and Black --- 入门搜索 BFS解法

    HDU 1312 题目大意: 一个地图里面有三种元素,分别为"@",".","#",其中@为人的起始位置,"#"可以想象 ...

  3. HDU 1312 Red and Black --- 入门搜索 DFS解法

    HDU 1312 题目大意: 一个地图里面有三种元素,分别为"@",".","#",其中@为人的起始位置,"#"可以想象 ...

  4. 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 ...

  5. HDU 1312 Red and Black(最简单也是最经典的搜索)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1312 Red and Black Time Limit: 2000/1000 MS (Java/Oth ...

  6. 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 ...

  7. 题解报告:hdu 1312 Red and Black(简单dfs)

    Problem Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...

  8. 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 ...

  9. HDU 1312 Red and Black(经典DFS)

    嗯... 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 一道很经典的dfs,设置上下左右四个方向,读入时记下起点,然后跑dfs即可...最后答 ...

  10. HDU 1312 Red and Black (DFS & BFS)

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 题目大意:有一间矩形房屋,地上铺了红.黑两种颜色的方形瓷砖.你站在其中一块黑色的瓷砖上,只能向相 ...

随机推荐

  1. Task Execution and Scheduling In SpringBoot

    开天辟地 Task Execution and Scheduling In the absence of an Executor bean in the context, Spring Boot au ...

  2. 移动端APP组件化架构实践

    前言 对于中大型移动端APP开发来讲,组件化是一种常用的项目架构方式.个人最近几年在工作项目中也一直使用组件化的方式来开发,在这过程中也积累了一些经验和思考.主要是来自在日常开发中使用组件化开发遇到的 ...

  3. 盘古大模型加持,华为云开天aPaaS加速使能千行百业应用创新

    摘要:开天aPaaS,让优秀快速复制,支撑开发者及伙伴上好云.用好云. 本文分享自华为云社区<盘古大模型加持,华为云开天aPaaS加速使能千行百业应用创新>,作者:开天aPaaS小助手. ...

  4. GaussDB技术解读丨高级压缩

    本文作者|华为云数据库GaussDB首席架构师 冯柯 [背景介绍] 数据压缩与关系数据库的结合,早已不是一个新鲜的话题,当前我们已经看到了各种各样数据库压缩的产品和解决方案.对于GaussDB来说,在 ...

  5. Angular: Error: NG0100: ExpressionChangedAfterItHasBeenChecked

    错误原因 当变更检测完成后又更改了表达式的值时,Angular就会抛出ExpressionChangedAfterItHasBeenCheckedError 错误,Angular只会在开发模式下抛出此 ...

  6. 关于selenium WebDriverException: Message: unknown error: DevToolsActivePort file doesnt exist 的解决方案

    文章参考: https://hant-kb.kutu66.com/others/post_13460379 在浏览器设置参数时加入如下两行代码 1 # 取消沙盒模式 2 options.add_arg ...

  7. Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-4_w0c665/PyQt5/

    错误: 解决方式:输入一下命令 1 pip3 install --upgrade setuptools 2 python3 -m pip install --upgrade pip 输入命令: 1 p ...

  8. Topic太多,RocketMQ炸了!

    网上博客常说,kafka的topic数量过多会影响kafka,而RocketMQ不会受到topic数量影响. 但是,果真如此吗? 最近排查一个问题,发现RocketMQ稳定性同样受到topic数量影响 ...

  9. 更快的训练和推理: 对比 Habana Gaudi®2 和英伟达 A100 80GB

    通过本文,你将学习如何使用 Habana Gaudi2 加速模型训练和推理,以及如何使用 Optimum Habana 训练更大的模型.然后,我们展示了几个基准测例,包括 BERT 预训练.Stabl ...

  10. 让nodejs开启服务更简单--express篇

    上一篇文章说到,nodejs获取客户端请求需要我们自己去处理请求参数.请求方式等,而在express框架内部集成了很多好用的方法,我们不需要从0开始编写各种处理逻辑,这样可以极大提高我们的开发效率~ ...