题目

//一道简单的广搜水题
#include<queue>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
struct tt
{
int x,y;
};
char mp[][];
int vis[][]; //看了题解,发现只有4个方向,而不是8个方向。。。。题目貌似都没说清楚
//int xx[8]={0,0,1,1,1,-1,-1,-1};
//int yy[8]={1,-1,0,1,-1,0,1,-1};
int xx[]={,,,-};
int yy[]={,-,,};
int one,two;
int n,m;
void bfs(int x,int y)
{
one=,two=;
queue<tt>q;
tt front,next,tmp;
front.x=x,front.y=y;
while(!q.empty())
q.pop();
q.push(front);
vis[x][y]=;
if(mp[x][y]=='o'){one++;}
else if(mp[x][y]=='v'){two++;}
while(!q.empty())
{
tmp=q.front();
q.pop();
for(int i=;i<;i++)
{
next.x=tmp.x+xx[i];
next.y=tmp.y+yy[i];
if(next.x<||next.x>=n||next.y<||next.y>=m)
{
one=,two=;return;
}
else if(mp[next.x][next.y]!='#'&&vis[next.x][next.y]==)
{
vis[next.x][next.y]=;
if(mp[next.x][next.y]=='o'){one++;}
else if(mp[next.x][next.y]=='v'){two++;}
q.push(next);
}
}
}
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(vis,,sizeof(vis));
for(int i=;i<n;i++)
scanf("%s",mp[i]);
int ansone=,anstwo=;
for(int i=;i<n-;i++)
{
for(int j=;j<m-;j++)
{
if(vis[i][j]==&&mp[i][j]!='#')
{
bfs(i,j);
if(one==two)one=two=;
else if(one>two)two=;
else if(two>one)one=;
ansone+=one;
anstwo+=two;
}
}
}
printf("%d %d\n",ansone,anstwo);
}
return ;
}

HDU 2267 How Many People Can Survive(广搜,简单)的更多相关文章

  1. HDU 1010 Tempter of the Bone (广搜+减枝)

    题目链接 Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. How ...

  2. hdu 1253:胜利大逃亡(基础广搜BFS)

    胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  3. hdu 2717:Catch That Cow(bfs广搜,经典题,一维数组搜索)

    Catch That Cow Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  4. hdu 1180:诡异的楼梯(BFS广搜)

    诡异的楼梯 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Subm ...

  5. HDU 3152 Obstacle Course(优先队列,广搜)

    题目 用优先队列优化普通的广搜就可以过了. #include<stdio.h> #include<string.h> #include<algorithm> usi ...

  6. DFS-BFS(深搜广搜)原理及C++代码实现

    深搜和广搜是图很多算法的基础,很多图的算法都是从这两个算法中启发而来. 深搜简单地说就是直接一搜到底,然后再回溯,再一搜到底,一直如此循环到没有新的结点. 广搜简单地说就是一层一层的搜,像水的波纹一样 ...

  7. hdu 5025 Saving Tang Monk 状态压缩dp+广搜

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092939.html 题目链接:hdu 5025 Saving Tang Monk 状态压缩 ...

  8. hdu 5094 Maze 状态压缩dp+广搜

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092176.html 题目链接:hdu 5094 Maze 状态压缩dp+广搜 使用广度优先 ...

  9. Combine String HDU - 5707 dp or 广搜

    Combine String HDU - 5707 题目大意:给你三个串a,b,c,问a和b是不是恰好能组成c,也就是a,b是不是c的两个互补的子序列. 根据题意就可以知道对于c的第一个就应该是a第一 ...

随机推荐

  1. linux下的C语言开发(gdb调试)

    原文: http://blog.csdn.net/feixiaoxing/article/details/7199643 用gdb调试多进程的程序会遇到困难,gdb只能跟踪一个进程(默认是跟踪父进程) ...

  2. spring boot项目Intellij 打包

    spring boot项目Intellij 打包 学习了:http://blog.csdn.net/hzt_fighting_up/article/details/78174291 在edit con ...

  3. MySQL批量SQL插入各种性能优化

    对于一些数据量较大的系统.数据库面临的问题除了查询效率低下,还有就是数据入库时间长.特别像报表系统,每天花费在数据导入上的时间可能会长达几个小时或十几个小时之久.因此.优化数据库插入性能是非常有意义的 ...

  4. 【cocos2d-x 3.7 飞机大战】 决战南海I (十) 游戏主场景

    主场景要包括其它类的头文件 #include "cocos2d.h" #include "MyPlane.h" #include "Bullet.h& ...

  5. json、js数组真心不是想得那么简单

    之前因为做前台的东西比較少,对于json和js数组的认识仅局限于一种固定格式.这样的固定的思维在开发前台时,特别是近期使用highcharts插件时.让我感到特别不明确.通过查询最终心头的疙瘩解开了. ...

  6. phoenixframe自己主动化測试平台对div弹出框(如弹出的div登陆框)的处理

    package org.phoenix.cases; import java.util.LinkedList; import org.phoenix.action.WebElementActionPr ...

  7. OTA升级中关于update.zip包的一些总结【转】

    本文转载自:http://429564140.iteye.com/blog/2337165 update.zip包整理 一. update.zip包的目录结构           |----boot. ...

  8. Coursera Algorithms week1 查并集 练习测验:3 Successor with delete

    题目原文: Given a set of n integers S = {0,1,…,N-1}and a sequence of requests of the following form: Rem ...

  9. centos安装lamp步骤还可以

    1. 用yum安装Apache,Mysql,PHP. 1.1安装Apache yum install httpd httpd-devel 安装完成后,用/etc/init.d/httpd start  ...

  10. JS代码放在哪里比较好!

    在页面上加上<script></script>只有2个地方:head中,body体中 如果外部的JS文件,在head中加,写页面特效js放在body后面. <html&g ...