POJ 1979 简单dfs||bfs
2013-03-27 21:11
513 查看
//题意:求从@出发的连续的'.'的个数。
分析:直接用dfs。
感悟:我很水啊,这题敲了半天。加油啊,亲。
View Code
分析:直接用dfs。
感悟:我很水啊,这题敲了半天。加油啊,亲。
View Code
#include<cstdio> #include<cstring> #include<iostream> using namespace std; #define maxn 110 int n,m; char str[maxn][maxn]; int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}}; int sum; void dfs(int s,int e){ for(int i=0;i<4;i++){ int xx=s+dir[i][0]; int yy=e+dir[i][1]; printf("xx=%d yy=%d\n",xx,yy); if(xx<0||xx>=m||yy<0||yy>=n){ continue; } if(str[xx][yy]=='.'){ sum++; str[xx][yy]='#'; dfs(xx,yy); } } } int main(){ while(scanf("%d%d",&n,&m)!=EOF){ int si,sj; if(n==0&&m==0) break; for(int i=0;i<m;i++){ scanf("%s",str[i]); for(int j=0;j<n;j++){ //scanf if(str[i][j]=='@'){ si=i; sj=j; } } //dfs(si,sj); } sum=1; str[si][sj]='#'; dfs(si,sj); printf("%d\n",sum); } return 0; }
相关文章推荐
- POJ 1979 简单dfs||bfs
- poj1979 水题简单dfs
- poj2688 Cleaning Robot 简单BFS+DFS
- POJ 1979 基础搜索 DFS\BFS 一
- 17 - 01 - 05 POJ 1979 (简单DFS)
- POJ 1979 3669 DFS BFS
- POJ 1979 Red and Black (DFS的简单应用)
- POJ 1979(简单dfs)
- (水)POJ-1979 Red and Black(dfs,bfs)
- poj 1979DFS&&BFS
- POJ 1979 Red and Black (简单dfs)
- POJ 1979 dfs和bfs两种解法
- poj 1979 简单dfs
- poj 1979 Red and Black (简单BFS)
- poj 1979 [ BFS 32ms 数据范围的事,可能造成 dfs 比 bfs 快了! ]
- poj 3984 迷宫问题【BFS && DFS】【简单】
- POJ 2243 简单搜索 (DFS BFS A*)
- poj-1979 && hdoj - 1312 Red and Black (简单dfs)
- POJ 1979 Red and Black(BFS or DFS)
- poj1562 Oil Deposits 简单搜索,dfs和bfs都行,我用的bfs