博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1312 (BFS搜索模板题)
阅读量:7070 次
发布时间:2019-06-28

本文共 1091 字,大约阅读时间需要 3 分钟。

题目链接: 

题目大意:问迷宫中有多少个点被访问。

解题思路

DFS肯定能水过去的。这里就拍了一下BFS。

然后发现自己BFS访问标记有问题,导致某些点被重复访问了。

赶紧改了一下。

 

#include "cstdio"#include "queue"#include "string"#include "cstring"#include "iostream"using namespace std;int n,m,sx,sy,map[25][25],dir[4][2]={-1,0,1,0,0,-1,0,1},cnt;bool vis[25][25];struct status{    int x,y;    status(int x,int y):x(x),y(y) {}};void bfs(int x,int y){    queue
Q; Q.push(status(sx,sy)); vis[sx][sy]=true; while(!Q.empty()) { cnt++; status t=Q.front();Q.pop(); for(int s=0;s<4;s++) { int X=t.x+dir[s][0],Y=t.y+dir[s][1]; if(vis[X][Y]||X<0||X>n||Y<0||Y>m||!map[X][Y]) continue; vis[X][Y]=true; Q.push(status(X,Y)); } }}int main(){ //freopen("in.txt","r",stdin); ios::sync_with_stdio(false); string tt; while(cin>>m>>n&&n) { cnt=0; memset(vis,0,sizeof(vis)); for(int i=1;i<=n;i++) { cin>>tt; for(int j=0;j

 

1869483 2014-10-14 14:49:59 Accepted 15MS 292K C++

转载于:https://www.cnblogs.com/neopenx/p/4024419.html

你可能感兴趣的文章
分布式搜索方案选型
查看>>
AIR文件操作(二):使用文件对象操作文件和目录
查看>>
mongodb的删除语句
查看>>
Linux 实用技巧
查看>>
hadoop-
查看>>
团队博客
查看>>
4.Struts2中Action的三种访问方式
查看>>
delphi 10.3 IOS中英文错位
查看>>
初识RabbitMQ
查看>>
“Linux内核分析”实验二
查看>>
WCF使用MSMQ通信
查看>>
前后端分离djangorestframework——权限组件
查看>>
redis去重方案
查看>>
内连接和外连接
查看>>
RT-Thread--内核基础
查看>>
PC键盘在Mac下Command/Option键切换
查看>>
数字签名和验签的详细过程
查看>>
漫谈《信号与系统》
查看>>
POJ 1742 Coins(多重背包,优化)
查看>>
内容不随模态框滚动
查看>>