hdu 5706 GirlCat(BFS)
Under the influence of Kotori, many girls and cats are playing ``Hide and Seek'' together.
Koroti shots a photo. The size of this photo is n×mn×m, each pixel of the photo is a character of the lowercase(from `a' to `z').
Kotori wants to know how many girls and how many cats are there in the photo.
We define a girl as -- we choose a point as the start, passing by 4 different connected points continuously, and the four characters are exactly ``girl'' in the order.
We define two girls are different if there is at least a point of the two girls are different.
We define a cat as -- we choose a point as the start, passing by 3 different connected points continuously, and the three characters are exactly ``cat'' in the order.
We define two cats are different if there is at least a point of the two cats are different.
Two points are regarded to be connected if and only if they share a common edge.
InputThe first line is an integer TT which represents the case number.
As for each case, the first line are two integers nn and mm, which are the height and the width of the photo.
Then there are nn lines followed, and there are mm characters of each line, which are the the details of the photo.
It is guaranteed that:
TT is about 50.
1≤n≤10001≤n≤1000.
1≤m≤10001≤m≤1000.
∑(n×m)≤2×106∑(n×m)≤2×106.
OutputAs for each case, you need to output a single line.
There should be 2 integers in the line with a blank between them representing the number of girls and cats respectively.
Please make sure that there is no extra blank.
Sample Input
3
1 4
girl
2 3
oto
cat
3 4
girl
hrlt
hlca
Sample Output
1 0
0 2
4 1
题目大意:根据输入的字符矩阵,分别找到girl和cat字符串的数量。
解题思路:找到一个起始点,直接进行搜索,查找接下去的字母。
#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstdio>
#include<time.h>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;
char a[][];
int d[][]={{-,},{,},{,},{,-}};
struct node
{
int x,y;
char c;
};
queue<node>q;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
cin>>a[i][j];
}
}
while(!q.empty ()) q.pop();
int sg=,sc=;
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(a[i][j]=='g')
{
node p;
p.x=i;
p.y=j;
p.c='g';
q.push(p);
}
if(a[i][j]=='c')
{
node p;
p.x=i;
p.y=j;
p.c='c';
q.push(p);
}
}
}
while(!q.empty())
{
node p=q.front ();
q.pop();
char c=p.c;
for(int i=;i<;i++)
{
int xx=p.x+d[i][];
int yy=p.y+d[i][];
if(xx<||yy<||xx>n||yy>m) continue;
char cc=a[xx][yy];
if((c=='g'&&cc=='i')||(c=='i'&&cc=='r')||(c=='c'&&cc=='a'))
{
node pp;
pp.x=xx;
pp.y=yy;
pp.c=cc;
q.push(pp);
}
if(c=='r'&&cc=='l')
{
sg++;
}
if(c=='a'&&cc=='t')
{
sc++;
}
}
}
cout<<sg<<" "<<sc<<endl;
}
return ; }
hdu 5706 GirlCat(BFS)的更多相关文章
- HDU 5706 GirlCat (DFS,暴力)
题意:给定一个n*m的矩阵,然后问你里面存在“girl”和“cat”的数量. 析:很简单么,就是普通搜索DFS,很少量.只要每一个字符对上就好,否则就结束. 代码如下: #include <cs ...
- HDU - 5706 - Girlcat - 简单搜索 - 新手都可以看懂的详解
原题链接: 大致题意:给你一个二维字符串,可以看成图:再给两个子串“girl”和“cat”,求图中任意起点开始的不间断连接起来的字母构成的两个子串的分别的个数:连接的方向只有不间断的上下左右. 搜索函 ...
- HDU(4528),BFS,2013腾讯编程马拉松初赛第五场(3月25日)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4528 小明系列故事——捉迷藏 Time Limit: 500/200 MS (Java/O ...
- hdu 1072 Nightmare (bfs+优先队列)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1072 Description Ignatius had a nightmare last night. H ...
- HDU 3533 Escape bfs 难度:1
http://acm.hdu.edu.cn/showproblem.php?pid=3533 一道普通的bfs,但是由于代码实现出了bug还是拖了很久甚至对拍了 需要注意的是: 1.人不能经过炮台 2 ...
- hdu 2389(最大匹配bfs版)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2389 思路:纯裸的一个最大匹配题,不过悲摧的是以前一直用的dfs版一直过不了,TLE无数次啊,然后改成 ...
- HDU 1495 非常可乐 BFS 搜索
http://acm.hdu.edu.cn/showproblem.php?pid=1495 题目就不说了, 说说思路! 倒可乐 无非有6种情况: 1. S 向 M 倒 2. S 向 N 倒 3. N ...
- hdu 4856 Tunnels(bfs+状态压缩)
题目链接:hdu 4856 Tunnels 题目大意:给定一张图,图上有M个管道,管道给定入口和出口,单向,如今有人想要体验下这M个管道,问最短须要移动的距离,起点未定. 解题思路:首先用bfs处理出 ...
- HDU 1242 Rescue(BFS),ZOJ 1649
题目链接 ZOJ链接 Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The ...
随机推荐
- Spring 自定义标签配置
前景:经常使用一些依赖于Spring的组件时,发现可以通过自定义配置Spring的标签来实现插件的注入,例如数据库源的配置,Mybatis的配置等.那么这些Spring标签是如何自定义配置的?学习Sp ...
- linux中的权限管理命令
一. 改变文件或目录的权限:chmod 命令详解 命令名称:chmod 命令所在路径:/bin/chmod 执行权限:所有用户 语法:chmod [{ugoa}{+-=}{rwx}] [文件或目录] ...
- 【spark】分区
RDD是弹性分布式数据集,通常RDD很大,会被分成多个分区,保存在不同节点上. 那么分区有什么好处呢? 分区能减少节点之间的通信开销,正确的分区能大大加快程序的执行速度. 我们看个例子 首先我们要了解 ...
- 【SQL查询】查询结果翻译成其他值_decode
decode()函数简介: 主要作用:将查询结果翻译成其他值(即以其他形式表现出来,以下举例说明): 使用方法: Select decode(columnname,值1,翻译值1,值2,翻译值2,.. ...
- POSIX线程同步
在posix编程中,如果在不同的线程中几乎同一时间操作同一个变量的时候,就会出现不同步. 如何解决这样的问题,这里需要用到互斥量,互斥锁的概念.请看UNIX环境高级编程P299页 #include & ...
- js 变量与属性的区别
在全局作用域下, 表明全局变量x,属性b,都是window的属性,因为在全局作用域下,浏览器默认会创建一个window对象. 说明变量x不能通过delete进行删除,但是属性y可以通过delete进行 ...
- OneDrive网页版打不开的解决办法
发现OneDrive文件被误删了,想去网页版找回历史文件,发现网页版无法打开,而客户端是可以正常使用的,于是猜测是域名指向的主IP被封了,于是想通过客户端的IP访问 第一步,WireShark抓包 第 ...
- Python判断unicode是汉字,数字,英文,或者其他字符
功能: 判断unicode是否是汉字,数字,英文,或者是否是(汉字,数字和英文字符之外的)其他字符. 全角.半角符号相互转换. 全角.半角? 全角--指一个字符占用两个标准字符位置. 汉字字符和规定了 ...
- 前端之jQuery02
文档操作 重点:创建标签,jQuery里面没有这个方法 内部(子标签) 添加到指定元素内部后面 $(A).append(B): // B作为A的最后一个儿子元素:(把B追加到A) $(A).appen ...
- PS基础教程[6]如何快速制作一寸照片
一寸照片使我们经常会用到的,很多的证件照都是使用一寸的照片作为存档的.写这个经验也是因为刚刚有网友求助做一寸照片,所以就顺便写个经验.废话不多说了,进入正题,PS基础教程之快速制作一寸的照片. 制作方 ...