poj1979
来源:互联网 发布:电脑包 知乎 编辑:程序博客网 时间:2024/05/20 18:41
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
const int maxn=25,maxm=25;
int n,m,ans;
string map[maxn];
bool visited[maxn][maxm];
void search(int row,int col)
{
if(row<0||row>=n||col<0||col>=m||map[row][col]=='#'||visited[row][col])
return;
visited[row][col]=true;
++ans;
search(row-1,col);
search(row+1,col);
search(row,col-1);
search(row,col+1);
}
int main()
{
cin>>m>>n;
while(m||n)
{
int row,col;
for(int i=0;i<n;i++)
{
cin>>map[i];
for(int j=0;j<m;j++)
{
if(map[i][j]=='@')
{
row=i;
col=j;
}
}
}
memset(visited,false,sizeof(visited));
ans=0;
search(row,col);
cout<<ans<<endl;
cin>>m>>n;
}
return 0;
}
#include<string>
#include<cstring>
using namespace std;
const int maxn=25,maxm=25;
int n,m,ans;
string map[maxn];
bool visited[maxn][maxm];
void search(int row,int col)
{
if(row<0||row>=n||col<0||col>=m||map[row][col]=='#'||visited[row][col])
return;
visited[row][col]=true;
++ans;
search(row-1,col);
search(row+1,col);
search(row,col-1);
search(row,col+1);
}
int main()
{
cin>>m>>n;
while(m||n)
{
int row,col;
for(int i=0;i<n;i++)
{
cin>>map[i];
for(int j=0;j<m;j++)
{
if(map[i][j]=='@')
{
row=i;
col=j;
}
}
}
memset(visited,false,sizeof(visited));
ans=0;
search(row,col);
cout<<ans<<endl;
cin>>m>>n;
}
return 0;
}
- POJ1979
- poj1979
- POJ1979
- POJ1979
- poj1979
- poj1979
- poj1979
- poj1979
- poj1979
- poj1979
- poj1979
- 【POJ1979】
- poj1979
- POJ1979
- poj1979--DFS
- poj1979 DFS
- dfs--poj1979
- POJ1979题解
- u-boot-linaro-stable命令列表
- UITabBarController 获得selecdIndex
- 雷军:我没有足够勇气面对小米爆炸式增长(转)
- json对象与字符串之间的转换
- 常用的快速Web原型图设计工具
- poj1979
- 代码规范
- Update-rc.d 命令用法详解
- MFC UpdateData(FALSE)和UpdateData(TRUE)的作用
- ArcGIS Flex API进行缓冲分析的讨论
- JAVA打包软件exe4j使用教程
- 对象写入xml,scoket进行通信
- xcode真机测试
- 黑马程序员——面向对象学习(2)