hdu 1312 Red and Black(搜索)
来源:互联网 发布:华悦网络加速器怎么样 编辑:程序博客网 时间:2024/06/07 13:17
这是一道非常中规中矩的题目,没有太多值得说的地方。不过写的时候发现对很多基础概念的理解不是很清晰,浪费了很多时间。
#include<stdio.h>#include<queue>using namespace std;struct node{int x,y;};char map[25][25];int dir[4][2]={1,0, 0,1, 0,-1, -1,0};int m,n,ans;int x,y;int judge(int x,int y){if(x>=0&&x<n&&y>=0&&y<m&&map[x][y]=='.')return 1;return -1;}int bfs(){int i;node cur,next;queue<node>q;ans=1;cur.x=x;cur.y=y;map[x][y]='#';q.push(cur);while(!q.empty()){cur=q.front();q.pop();for(i=0;i<4;i++){next.x=x=cur.x+dir[i][0];next.y=y=cur.y+dir[i][1];if(judge(x,y)==1){ans++;map[x][y]='#';q.push(next);}}}return ans;}int main(){int i,j;while(scanf("%d%d",&m,&n),m||n){getchar();for(i=0;i<n;i++){if(i!=0)getchar();for(j=0;j<m;j++){scanf("%c",&map[i][j]);if(map[i][j]=='@'){x=i;y=j;}}}ans=bfs();printf("%d\n",ans);}return 0;}
- hdu 1312 Red and Black(搜索)
- HDU 1312 Red and Black(搜索)
- HDu 1312深度搜索---Red and Black
- HDU 1312 Red and Black(简单搜索)
- Red and Black(搜索)
- Red and Black(hdu 1312)
- HDU 1312 Red and Black (BFS)
- HDU 1312 Red and Black(深搜)
- hdu 1312 Red and Black(深搜)
- HDU 1312 -- Red and Black(dfs)
- HDU - 1312 Red and Black (dfs)
- hdu 1312Red and Black(DFS)
- HDU 1312 Red and Black(DFS)
- hdu 1312 Red and Black(dfs)
- HDU 1312 Red and Black(BFS)
- HDU 1312 Red and Black(水题)
- HDU 1312 Red and Black(DFS)
- hdu 1312 Red and Black (dfs)
- pg_dump实例详解
- java的B/S模式日志log4j配置及路径
- poj 1742 硬币面值 拼凑 重解 poj 1014
- cakephp2 MeioUpload 图片上传简单应用
- ZOJ 3686 A A Simple Tree Problem
- hdu 1312 Red and Black(搜索)
- 一天一linux命令(11) ln 链接文件
- hibernate isolation 幻读
- jquery.fullCalendar官方文档翻译(一款小巧好用的日程管理日历, 可集成Google Calendar)
- Hibernate 查询多个字段返回的list如何转为自定义对象
- 怎样解题表
- 排序算法小结
- 根据文件编码格式解析html文件
- jrebel 使用