2013寒假练习 1038 Red and Black
2013-02-16 21:23
246 查看
地址:http://acm.bit.edu.cn/mod/programming/view.php?id=689
水题,最基本的bfs。
水题,最基本的bfs。
#include<iostream> #include<queue> using namespace std; typedef struct NODE { int x,y; }node; node temp,now; char map[25][25]; bool flag[25][25]; int dir[4][2]={0,1,0,-1,-1,0,1,0}; int main() { int m,n,i,j; while(scanf("%d%d",&n,&m),m||n) { int ans=0; queue<node>q; memset(flag,0,sizeof(flag)); for(i=0;i<m;i++) { getchar(); for(j=0;j<n;j++) { scanf("%c",&map[i][j]); if(map[i][j]=='@') temp.x=i,temp.y=j,q.push(temp),ans++,flag[i][j]=1; } } while(!q.empty()) { temp=q.front(); for(i=0;i<4;i++) { now.x=temp.x+dir[i][0],now.y=temp.y+dir[i][1]; if(now.x>=0&&now.x<m&&now.y>=0&&now.y<n&&!flag[now.x][now.y]&&map[now.x][now.y]=='.') { q.push(now); flag[now.x][now.y]=1,ans++; } } q.pop(); } printf("%d\n",ans); } return 0; }
相关文章推荐
- J - Red and Black 寒假练习1-J
- bit 1038 Red and Black
- 练习系统 实验四 red and black
- Java程序练习-Red and Black
- HPU DFS + BFS 专项练习A - Red and Black HDU - 1312
- 课程练习二-1016-Red and Black
- 1038 Red and Black
- Red and Black(DFS)
- POJ 1979 - Red and Black
- Red and Black
- BFS入门-Red and Black
- POJ - 1979 Red and Black
- poj 1979 Red and Black
- hdu1312 poj1979 Red and Black(DFS)
- HDOJ 1312题Red and Black
- DFS - Red and Black
- HDU 1312 Red and Black
- POJ 1979 - Red and Black 深度优先搜索
- POJ-1979(DFS) Red and Black
- HDOJ 1312 Red and Black