POJ-1979 Red and Black
来源:互联网 发布:qt5.7串口编程实例 编辑:程序博客网 时间:2024/06/06 17:30
dfs简单应用
#include<iostream>#include<cstring>#include<stack>#include<queue>#define MAX 21using namespace std;int ans;char a[MAX][MAX];void dfs(int x,int y){ans++;//每搜索一个点,次数加1,最后输出总的搜索次数就是有多少个’.‘a[x][y]='6';//把已经搜索过的点替换掉,下次就不会再搜这个点了if(a[x+1][y]=='.') dfs(x+1,y);if(a[x-1][y]=='.') dfs(x-1,y);if(a[x][y+1]=='.') dfs(x,y+1);if(a[x][y-1]=='.') dfs(x,y-1);}int main(){int W,H;int tx,ty;while(cin>>W>>H&&W&&H){memset(a,0,sizeof(a));for(int i=0;i<H;i++){for(int j=0;j<W;j++){cin>>a[j][i];if(a[j][i]=='@'){tx=j;ty=i;}//记录@的位置}}ans=0;dfs(tx,ty);cout<<ans<<endl;}return 0;}
0 0
- 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
- 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
- poj 1979 Red and Black
- POJ 1979 Red and Black
- poj 1979Red and Black
- POJ 1979 Red and Black
- POJ 1979 Red and Black
- POJ 1979-Red and Black
- 【解题报告】AIM Tech Round 3 (Div. 2)(先占个位置,里面暂时什么也没有)
- MATLAB中floor、round、ceil、fix区别
- Oracle忘记密码增麽办???
- iOS逆向工程三:苹果私有API的获取
- nginx应用反向代理负载均衡
- POJ-1979 Red and Black
- 疯狂Java笔记:3.2 标识符和关键字
- 【小结】机器学习中的正则化范数 -- L1范数与L2范数
- 从0到1:我是如何在一年内无师自通机器学习的?
- 设计模式笔记十:装饰器模式
- PAT 1098-Insertion or Heap Sort (25)
- 编程题训练3
- MongoDB文档翻译-聚集-聚集管道优化
- 【解题报告】Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)(先占个位置,里面暂时什么都没有)