HDU1312 Red and Black 搜索入门
来源:互联网 发布:mysql 主主 维护 编辑:程序博客网 时间:2024/05/16 09:37
一道很简单的搜索入门题
题目大意是指把一个广场分为红黑两种颜色的砖,人只能在黑砖上移动,给你一个起点,问你最多能走多少块黑砖。
#include<iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;int cont, m, n, sx,sy;char maze[21][21];int xm[4]={1,0,-1,0},ym[4]={0,1,0,-1};void dfs(int x, int y){ int tx, ty, j; cont++; for(int i=0;i<4;i++) { tx=x+xm[i];ty=y+ym[i]; if(tx<0||tx>=n||ty<0||ty>=m||maze[tx][ty]=='#') continue; maze[tx][ty]='#'; dfs(tx,ty); }}int main(){ while(scanf("%d%d",&m,&n)!=EOF&&m&&n) { cont=0; for(int i=0;i<n;i++) { getchar(); for(int j=0;j<m;j++) { scanf("%c",&maze[i][j]); if(maze[i][j]=='@') { sx=i;sy=j; } } } maze[sx][sy]='#'; dfs(sx,sy); printf("%d\n",cont); } return 0;}
0 0
- HDU1312 Red and Black 搜索入门
- HDU1312 Red and Black 搜索
- hdu1312 Red and Black 简单搜索
- hdu1312 Red and Black(简单搜索)
- Hdu1312 - Red and Black - 广度优先搜索
- hdu1312 Red and Black(搜索基础)
- hdu1312 Red and Black(入门dfs)
- HDU1312( Red and Black )
- hdu1312 Red and Black
- HDU1312 Red and Black
- HDU1312:Red and Black
- HDU1312 Red and Black
- Red and Black(hdu1312)
- HDU1312 Red and Black
- HDU1312 Red and Black
- HDU1312-Red and Black
- hdu1312 Red and Black
- hdu1312 Red and Black
- url传递含有参数的参数
- MD5加解密
- 黑马程序员--ios block语法介绍
- Codeforces 好题
- Android UI简单美化
- HDU1312 Red and Black 搜索入门
- 深入Java集合学习系列:HashMap的实现原理
- Linux编写Shell脚本自动同步svn并发布maven项目-Linux服务器用户设置
- 看源码学知识(不定期更新)
- WPF 之消息队列
- [leetcode][hash] Single Number II
- Android学习笔记--SharedPreferences的使用
- 51单片机项目 模拟智能传送装置
- 23.创建ViewController的三种方式