POJ——1979(深搜)
来源:互联网 发布:淘宝网店面设计 编辑:程序博客网 时间:2024/06/04 19:18
题目链接:http://poj.org/problem?id=1979
源代码:
#include<iostream>
using namespace std;
char a[1005][1005];
int X[5]={-1,0,1,0};
int Y[5]={0,-1,0,1};
int m,n;
int check(int x,int y)
{
if(x<0||y<0||x>=m||y>=n)
return 0;
return 1;
}
int dfs(int x,int y,int count)
{
count++;
a[x][y]='#';
int xx,yy;
for(int i=0;i<4;i++)
{
xx=x+X[i];
yy=y+Y[i];
if(!check(xx,yy)) continue;
if(a[xx][yy]=='.')
count=dfs(xx,yy,count);
}
//cout<<" "<<count<<endl;
return count;
}
int main()
{
int i,j,k;
int count;
while(cin>>n>>m&&m!=0&&n!=0)
{
count=0;
for(i=0;i<m;i++)
cin>>a[i];
for(i=0;i<m;i++)
for(j=0;j<n;j++)
if(a[i][j]=='@')
{
count=dfs(i,j,count);
}
cout<<count<<endl;
}
}
- POJ——1979(深搜)
- POJ——2488(深搜)
- POJ 1979 —— 搜索
- POJ—2253(Frogger)
- POJ 1979 - Red and Black(深搜)
- POJ 1979 Red and Black (深搜)
- POJ 1979 深搜
- POJ - 1979(深搜)
- POJ——1979Red and Black
- poj之旅——1979
- Find The Multiple ——深搜POJ
- POJ 1979(递归)
- poj 1979(DFS)
- ACM——POJ 3295 (Tautology)
- POJ ——1465(宽度搜索)
- POJ——3278(宽搜)
- POJ——2488(深度搜索)
- POJ——2635(数论)
- 深入分析 enq: TX - row lock contention
- WM_CREATE和WM_INITDIALOG消息响应函数之区别,以及MFC应用程序中处理消息的...
- Ubuntu12.04安装基础教程(图文)
- MinGW和MSYS的自动安装
- android-使用ActivityGroup来切换Activity和Layout - 随心
- POJ——1979(深搜)
- 学习C++ 初学者值得推荐! 转自 : sxhelijian
- 串口调试助手上输入数据0-9,然后再数码管显示(汇编语言版本)
- Azure:用LoadBalancerProbe自定义负载均衡器
- ZOJ——2412(深搜)
- ubuntu10.04下gtk2.0的配置
- 画图时用到过的一些方法 写的很乱 补充的也需要很多 以后再整理完整
- ZOJ——1091(宽搜)
- 如何在CSDN博客栏目设置滚动字幕——我的CSDN博客(1)