HDU 2267 How Many People Can Survive(广搜,简单)
//一道简单的广搜水题
#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(广搜,简单)的更多相关文章
- HDU 1010 Tempter of the Bone (广搜+减枝)
题目链接 Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. How ...
- hdu 1253:胜利大逃亡(基础广搜BFS)
胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- hdu 2717:Catch That Cow(bfs广搜,经典题,一维数组搜索)
Catch That Cow Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1180:诡异的楼梯(BFS广搜)
诡异的楼梯 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Subm ...
- HDU 3152 Obstacle Course(优先队列,广搜)
题目 用优先队列优化普通的广搜就可以过了. #include<stdio.h> #include<string.h> #include<algorithm> usi ...
- DFS-BFS(深搜广搜)原理及C++代码实现
深搜和广搜是图很多算法的基础,很多图的算法都是从这两个算法中启发而来. 深搜简单地说就是直接一搜到底,然后再回溯,再一搜到底,一直如此循环到没有新的结点. 广搜简单地说就是一层一层的搜,像水的波纹一样 ...
- hdu 5025 Saving Tang Monk 状态压缩dp+广搜
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092939.html 题目链接:hdu 5025 Saving Tang Monk 状态压缩 ...
- hdu 5094 Maze 状态压缩dp+广搜
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092176.html 题目链接:hdu 5094 Maze 状态压缩dp+广搜 使用广度优先 ...
- Combine String HDU - 5707 dp or 广搜
Combine String HDU - 5707 题目大意:给你三个串a,b,c,问a和b是不是恰好能组成c,也就是a,b是不是c的两个互补的子序列. 根据题意就可以知道对于c的第一个就应该是a第一 ...
随机推荐
- 一个神奇的PHP框架:Phalcon 之初识
前言 公司的APP响应速度比较慢,公司大神决定使用C语言编写的PHP框架Phalcon 代替原来的框架,响应速度有比较大的提升.以前只是听说过,没有深入的了解过.即然工作中有用到,便花点时间了解了下, ...
- [MongoDB]Python 操作 MongoDB
from pymongo import MongoClient mc = MongoClient('localhost',27017) db = mc.users db.users.save({'na ...
- saprk里面的action - aggregate
上一篇讲到了spark里面的action函数: Action列表: reduce collect count first take takeSample takeOrdered saveAsTextF ...
- [Jest] Use property matchers in snapshot tests with Jest
With the right process in place, snapshot tests can be a great way to detect unintended changes in a ...
- [Cypress] Interact with Hidden Elements in a Cypress Test
We often only show UI elements as a result of some user interaction. Cypress detects visibility and ...
- Top10Servlet
<span style="font-size:18px;">/** * Top10 * author:杨鑫 */ package servlet; import jav ...
- 线段树+离线 hdu5654 xiaoxin and his watermelon candy
传送门:点击打开链接 题意:一个三元组假设满足j=i+1,k=j+1,ai<=aj<=ak,那么就好的.如今告诉你序列.然后Q次询问.每次询问一个区间[l,r],问区间里有多少个三元组满足 ...
- redis client 2.0.0 pipeline 的list的rpop bug
描写叙述: redis client 2.0.0 pipeline 的list的rpop 存在严重bug,rpop list的时候,假设list已经为空的时候,rpop出来的Response依旧不为n ...
- luogu3225 [HNOI2012]矿场搭建
题目大意 给出一个有$n(n\leq 500)$个节点的无向图,一个满足条件的点集$V$会使得对于图中的每一个节点$u$,满足路径起点为$u$终点$v\in V$的路径集合$P_u$中总存在至少两条路 ...
- 10.0arcmap切片生成ptk步骤
注意:在制作之前需要点将图放到原本大小.并且保存一下不然容易造成数据丢失. 1.制作mxd 我们将待发布的数据,鼠标选中,拖入到ArcMap中间区域,单击保存. 可以对layers下面的图层进行改名. ...