HDU 1312 Red and Black 题解
//注意边界判断,调了好久
#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 题解的更多相关文章
- 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解法
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(最简单也是最经典的搜索)
传送门: 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)
Problem Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...
- 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 题目大意:有一间矩形房屋,地上铺了红.黑两种颜色的方形瓷砖.你站在其中一块黑色的瓷砖上,只能向相 ...
随机推荐
- Windows/DOS与Unix文件格式之间的相互转换(/r/n问题)
PS:今天遇到一个文件转换问题,现在将网上搜索到资料贴出来.. 第一个资料 Windows/DOS与Unix文件格式是不同的,问题一般就是出在/r/n问题上. 回车(CR)和换行(LF)符都是用来表示 ...
- Button按钮:得到鼠标焦点后自动放大,失去鼠标焦点后自动缩小_
作用 程序设计过程中,我们经常需要增加一些动态效果,以此改善用户的使用体验.本文将介绍一种方法,动态显示按钮状态,使其得到鼠标焦点后自动放大,失去鼠标焦点后自动缩小. 效果图 先放一张原图(鼠标还未移 ...
- hexo博客Yilia主题首页菜单中文乱码解决方案
方案一: 菜单设置成中文显示,编辑博客根目录下的_config.yml文件 设置language字段如下: language: zh-Hans 或者 language: zh-CN 取决于你的主题th ...
- 2023年CCPC河南省程序设计竞赛 mjh
首先,很荣幸有机会参加此次ccpc,虽然成绩很一般... 这次ccpc一共过了两道签到题.比赛开始就找到了a题,考察字符串的回文判断,通过调用c++库函数过了.第二道签到题类似于数学题.通过类似于找规 ...
- 小程序软键盘&SM2解密方式
小程序软键盘&SM2解密方式 转载请著名出处:https://www.cnblogs.com/funnyzpc/p/17572445.html SM2基本信息 私钥(primary key) ...
- 2021-7-12 VUE的增删改查功能简单运用
Vue增删改查简易实例 <!DOCTYPE html> <html> <head> <title> </title> <style t ...
- 需求太多处理不过来?MoSCoW模型帮你
一.MoSCoW模型是什么 MoSCoW模型是在项目管理.软件开发中使用的一种排序优先级的方法,以便开发人员.产品经理.客户对每个需求交付的重要性达成共识. MoSCoW是一个首字母缩略词,代表: M ...
- 超详细的mysql总结(DQL)
上一篇文章总结了 DDL.DML的使用,这一篇文章把剩下的 DQL 加上~ DQL(Data Query Language)即数据库查询语言,用来查询所需要的信息,在查询的过程中,需要判断所查询的 ...
- 「学习笔记」gdb 调试的简单操作
gdb是一个命令行下的.功能强大的调试器. 在学习 gdb 前,我们要知道几个最基本的 cmd 命令. cmd 首先,对于 win10 系统,我们按 Windows + R 键,打开运行窗口,在里面输 ...
- 基于Linux的三种防火墙(IPtables、Firewall、UFW)
学而不思则罔,思而不学则殆. 导航 IPtables Firewall UFW 对比总结 IPtables部分 1.IPtables 四表五链. 四表:filter.nat.raw.mangle. 五 ...