100114B
bfs
#include<iostream>
#include<queue>
#include<cstring>
#include<cstdio>
using namespace std;
const int dx[]={-,,,},dy[]={,,-,};
queue<int>q;
int n,m,ans,x,y;
int used[][];
char board[][];
void bfs(int a,int b)
{
q.push(a);q.push(b);
used[a][b]=;
while(!q.empty())
{
int x=q.front();q.pop();
int y=q.front();q.pop();
for(int i=;i<;i++)
{
int xx=x+dx[i];
int yy=y+dy[i];
if(board[xx][yy]=='-')
{
ans++;break;
}
}
for(int i=;i<;i++)
{
int xx=x+dx[i],yy=y+dy[i];
if(!used[xx][yy]&&board[xx][yy]=='+')
{
q.push(xx);q.push(yy);used[xx][yy]=;
}
}
}
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
cin>>n>>m;
memset(used,,sizeof(used));
memset(board,'',sizeof(board));
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
{
cin>>board[i][j];
used[i][j]=;
if(board[i][j]=='+')
{
x=i;y=j;
}
}
bfs(x,y);
cout<<ans<<endl;
fclose(stdin);
fclose(stdout);
return ;
}
100114B的更多相关文章
随机推荐
- Eclipse tooltip变黑的修正
- uva10001 Garden of Eden
Cellular automata are mathematical idealizations of physical systems in which both space and time ar ...
- Android中关于Volley的使用(五)从RequestQueue开始来深入认识Volley
在前面的几篇文章中,我们学习了如何用Volley去网络加载JSON数据,如何利用ImageRequest和NetworkImageView去网络加载数据,而关于Volley的使用,我们都是从下面一行代 ...
- Linux命令行
linux下C编程: GCC编译常用选项: -I dir:在头文件的搜索路径列表中添加dir目录. -L dir:在库文件的搜索路径列表中添加dir目录. -fPIC:该条命令使用相对地址. shel ...
- 在VisualStudio2013,2015中如何安装自定义项目模板
For example, I want to install EP prj template: AxWebProject.zip Copy AxWebProject.zip zip file into ...
- django整合原有的mysql数据库
虽然django适合从零开始构建一个项目,但有时候整合原有的数据库也在所难免,下面以django整合我的mysql作说明. mysql数据是我从京东上抓取的数据,数据表名为jd,演示如图 下面将jd整 ...
- zlog学习笔记(level_list)
level_list.h /** * */ #ifndef __zlog_level_list_h #define __zlog_level_list_h zc_arraylist_t *zlog_l ...
- 使用SecureCRT连接AWS EC2
AWS提供的XXX.pem文件, 如果使用Ubuntu等linux系统,直接使用ssh命令即可访问AWS上的Linux-EC2实例. $ ssh -i XXX.pem ec2-user@{IP/hos ...
- PAT 1006. 换个格式输出整数 (15)
让我们用字母B来表示"百".字母S表示"十",用"12...n"来表示个位数字n(<10),换个格式来输出任一个不超过3位的正整数.例 ...
- 表单 - Validatebox - 表单参数校验
$("input[name='username']").validatebox({ required: true,//必填 validType:'email'//要求用户名必须是一 ...