POJ 1979 简单dfs||bfs
来源:互联网 发布:linux oracle 进程 编辑:程序博客网 时间:2024/05/18 20:45
//题意:求从@出发的连续的'.'的个数。
分析:直接用dfs。
感悟:我很水啊,这题敲了半天。加油啊,亲。
View Code
#include<cstdio>#include<cstring>#include<iostream>using namespace std;#define maxn 110int 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
- poj 1979DFS&&BFS
- poj 3984 迷宫问题【BFS && DFS】【简单】
- POJ 1979 3669 DFS BFS
- POJ 1979(简单dfs)
- poj 1979Red and Black(BFS DFS)
- POJ 1979--DFS or BFS(水)
- POJ 1979 基础搜索 DFS\BFS 一
- poj 3083 DFS+DFS+BFS
- POJ 1062 BFS+DFS
- POJ 3083 BFS+DFS
- poj 3083 dfs+bfs
- poj 3083 bfs+dfs
- POJ 2308 DFS+BFS
- poj 3083 DFS+BFS
- POJ2386-简单BFS/DFS
- poj 3083 搜索 DFS,BFS
- POJ 3083图搜 bfs+dfs
- POJ 1789 prim求最小生成树
- CSS 随记
- POJ 1258 prim模版求最小生成树
- POJ3026 bfs+prim
- ZOJ2110 dfs+剪枝
- POJ 1979 简单dfs||bfs
- POJ 1562 dfs求连通分量的个数
- Arab and North African Region,2002(Snakes & ladders)
- POJ 2243 bfs
- POJ 1300 判断欧拉回路
- acm和做人有关系?
- POJ 1780 欧拉i回路判断&&输出欧拉回路
- fleury算法输出欧拉回路
- POJ 1511 spfa求最短回路