HDOJ 1312 Red and Black 基础DFS
来源:互联网 发布:域名cn可以个人注册吗 编辑:程序博客网 时间:2024/05/16 10:08
题目大意:
给你一张包含墙壁,路和起点的图。求所有能到达的点数(包括起点)。
题目分析:
最基本的DFS,用BFS也可以做,记得把起点算上,新手可以通过这道题熟悉DFS模板。
源代码:
#include<iostream>using namespace std;char map[25][25];int i,j,sx,sy,n,m;int dir[4][2]={1,0,0,1,-1,0,0,-1};int step;void dfs(int x,int y){ for(int i=0;i<4;i++) { int xx,yy; xx=x+dir[i][0]; yy=y+dir[i][1]; if(xx>=0&&xx<n&&yy>=0&&yy<m&&map[xx][yy]=='.') { step++; map[xx][yy]='#'; dfs(xx,yy); } }}int main(){ while(cin>>m>>n) { if(n==0&&m==0) break; getchar(); step=1; for(i=0;i<n;i++) { for(j=0;j<m;j++) { cin>>map[i][j]; if(map[i][j]=='@') { sx=i; sy=j; } } getchar(); } dfs(sx,sy); cout<<step<<endl; } return 0;}当前水平评级:2
0 0
- HDOJ 1312 Red and Black 基础DFS
- HDOJ 1312-Red and Black【基础DFS】
- HDOJ 1312 Red and Black (DFS)
- HDOJ--1312--Red and Black【DFS】
- hdoj 1312 Red and Black (DFS)
- HDOJ 题目1312 Red and Black(DFS)
- hdoj 1312 Red and Black【DFS】
- HDOJ 1312 Red and Black(简单dfs)
- hdoj 1312 Red and Black【dfs,回溯】
- HDOJ 1312 Red and Black (DFS)
- hdoj--1312--Red and Black(dfs)
- HDOJ 1312 Red and Black【dfs】
- HDOJ-1312(Red and Black)(dfs)
- HDOJ 1312 Red and Black (简单dfs)
- HDOJ 题目1312 Red and Black(dfs)
- HDOJ Red and Black 1312(入门级DFS)
- HDOJ 1312 Red and Black (简单dfs)
- HDOJ 1312 Red and Black (深搜 DFS)
- IOS开发—如何选择delegate,notification,KVO
- 多线程及其同步
- POJ2112 Optimal Milking 【最大流+二分】
- 实现半透明的popupwindow的源码
- IT人生 需要指引
- HDOJ 1312 Red and Black 基础DFS
- spring在web中如何运行1
- C#常用
- IOS 开发—CoreText实现图文混排和点击事件
- 【Java.Web】Servlet —— 避免Servlet的并发同步问题
- SQL窗口函數一例
- 在Windows的Tomcat环境下部署Solr 4.7.0
- HDU-4407-Sum(容斥原理)
- jira 安装步骤