POJ-1979-Red and Black
2013-05-16 15:10
429 查看
比较简单的DFS,直接搜索即可~
代码:
代码:
#include<cstdio> #include<cstring> #include<iostream> #include<queue> using namespace std; const int maxn=30; char map[maxn][maxn]; int r,c,sx,sy,ans,movex[4]={1,-1,0,0},movey[4]={0,0,-1,1}; bool vis[maxn][maxn]; void DFS(int x,int y) { if(map[x][y]=='#') return; ans++; for(int i=0;i<4;i++) { if(vis[x+movex[i]][y+movey[i]]) continue; vis[x+movex[i]][y+movey[i]]=1; DFS(x+movex[i],y+movey[i]); } } int main() { while(scanf("%d%d",&c,&r)&&(c+r)) { for(int i=0;i<=c+1;i++) map[0][i]=map[r+1][i]='#'; for(int i=0;i<=r+1;i++) map[i][0]=map[i][c+1]='#'; ans=0; memset(vis,0,sizeof(vis)); for(int i=1;i<=r;i++) { getchar(); for(int j=1;j<=c;j++) { scanf("%c",&map[i][j]); if(map[i][j]=='@') sx=i,sy=j; } } vis[sx][sy]=1; DFS(sx,sy); printf("%d\n",ans); } return 0; }
相关文章推荐
- POJ 1979-Red and Black [dfs] 《挑战程序设计竞赛》2.1
- Red and Black POJ - 1979
- POJ - 1979 Red and Black(DFS)
- 解题报告_POJ1979-red and black_深搜水题
- 【BFS】poj 1979 Red and Black
- poj 1979 Red and Black -dfs,回溯
- Poj 1979 Hdu 1312 Red and Black【dfs】
- POJ 1979 Red and Black(BFS or DFS)
- POJ-1979 Red and Black-走方砖
- POJ-1979 Red and Black
- [POJ] 1979 Red and Black
- poj 1979 Red and Black
- POJ_1979_Red and Black
- POJ-1979-Red and Black(DFS)
- poj 1979 Red and Black -- dfs
- poj 1979 Red and Black
- POJ 1979 Red and Black
- POJ1979 Red and Black 【深搜】
- POJ 1979:Red and Black
- POJ 1979 Red and Black