POJ1979
来源:互联网 发布:c语言深度剖析 第二版 编辑:程序博客网 时间:2024/05/20 19:33
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue>
#define maxn 40
using namespace std;
char map[maxn][maxn];
bool vis[maxn][maxn];
int n,m,ans;
void bfs( int x, int y)
{
if(vis[x][y] || map[x][y] == '#')
return ;
ans++;
vis[x][y] = true;
bfs(x-1,y);
bfs(x,y-1); bfs(x,y+1);
bfs(x+1,y);
}
int main( )
{
while(scanf("%d%d",&n, &m)!=EOF, n &&m)
{
ans = 0;
int i,j,x,y;
bool flag = 1;
memset(map,'#',sizeof(map));
memset(vis,false,sizeof(vis));
for( i = 1; i <= m; i++)
{
cin.get();
for( j = 1; j <= n; j++)
{
cin>>map[i][j];
if(map[i][j] == '@' && flag)
{
x = i;
y = j;
flag = 0;
}
}
}
bfs(x,y);
cout<<ans<<endl;
}
}
#include <stdio.h>
#include <string.h>
#include <queue>
#define maxn 40
using namespace std;
char map[maxn][maxn];
bool vis[maxn][maxn];
int n,m,ans;
void bfs( int x, int y)
{
if(vis[x][y] || map[x][y] == '#')
return ;
ans++;
vis[x][y] = true;
bfs(x-1,y);
bfs(x,y-1); bfs(x,y+1);
bfs(x+1,y);
}
int main( )
{
while(scanf("%d%d",&n, &m)!=EOF, n &&m)
{
ans = 0;
int i,j,x,y;
bool flag = 1;
memset(map,'#',sizeof(map));
memset(vis,false,sizeof(vis));
for( i = 1; i <= m; i++)
{
cin.get();
for( j = 1; j <= n; j++)
{
cin>>map[i][j];
if(map[i][j] == '@' && flag)
{
x = i;
y = j;
flag = 0;
}
}
}
bfs(x,y);
cout<<ans<<endl;
}
}
0 0
- POJ1979
- poj1979
- POJ1979
- POJ1979
- poj1979
- poj1979
- poj1979
- poj1979
- poj1979
- poj1979
- poj1979
- 【POJ1979】
- poj1979
- POJ1979
- poj1979--DFS
- poj1979 DFS
- dfs--poj1979
- POJ1979题解
- 用自家自己的电脑做网站服务器建立个人网站
- 重构 改善既有代码的设计:代码的坏
- Only the original thread that created a view hierarchy can touch its views的解决记录
- TCP连接的建立和终止
- 基于SOAP编写WebService客户端(一)
- POJ1979
- JavaScript设计模式之一封装
- Pascal's Triangle II
- J2SE-程序执行与内存图
- 什么叫网络透明性
- Java的运行原理
- show processes on system with ps
- 开源 iOS 项目分类索引大全
- 服务器架设:PPTPD/L2TP/IPSec VPN一键安装包 For CentOS 6