As a cute girl, Kotori likes playing ``Hide and Seek'' with cats particularly. 
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)的更多相关文章

  1. HDU 5706 GirlCat (DFS,暴力)

    题意:给定一个n*m的矩阵,然后问你里面存在“girl”和“cat”的数量. 析:很简单么,就是普通搜索DFS,很少量.只要每一个字符对上就好,否则就结束. 代码如下: #include <cs ...

  2. HDU - 5706 - Girlcat - 简单搜索 - 新手都可以看懂的详解

    原题链接: 大致题意:给你一个二维字符串,可以看成图:再给两个子串“girl”和“cat”,求图中任意起点开始的不间断连接起来的字母构成的两个子串的分别的个数:连接的方向只有不间断的上下左右. 搜索函 ...

  3. HDU(4528),BFS,2013腾讯编程马拉松初赛第五场(3月25日)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4528 小明系列故事——捉迷藏 Time Limit: 500/200 MS (Java/O ...

  4. hdu 1072 Nightmare (bfs+优先队列)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1072 Description Ignatius had a nightmare last night. H ...

  5. HDU 3533 Escape bfs 难度:1

    http://acm.hdu.edu.cn/showproblem.php?pid=3533 一道普通的bfs,但是由于代码实现出了bug还是拖了很久甚至对拍了 需要注意的是: 1.人不能经过炮台 2 ...

  6. hdu 2389(最大匹配bfs版)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2389 思路:纯裸的一个最大匹配题,不过悲摧的是以前一直用的dfs版一直过不了,TLE无数次啊,然后改成 ...

  7. HDU 1495 非常可乐 BFS 搜索

    http://acm.hdu.edu.cn/showproblem.php?pid=1495 题目就不说了, 说说思路! 倒可乐 无非有6种情况: 1. S 向 M 倒 2. S 向 N 倒 3. N ...

  8. hdu 4856 Tunnels(bfs+状态压缩)

    题目链接:hdu 4856 Tunnels 题目大意:给定一张图,图上有M个管道,管道给定入口和出口,单向,如今有人想要体验下这M个管道,问最短须要移动的距离,起点未定. 解题思路:首先用bfs处理出 ...

  9. HDU 1242 Rescue(BFS),ZOJ 1649

    题目链接 ZOJ链接 Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The ...

随机推荐

  1. MySQL无法启动几种常见问题小结

    问题1:目录.文件权限设置不正确 MySQL的$datadir目录,及其下属目录.文件权限属性设置不正确,导致MySQL无法正常读写文件,无法启动. 错误信息例如: 复制代码 代码如下:[code] ...

  2. mongodb笔记(一) 分片 &&文档连接

    版本:mongodb3.4 ; 分片: 工作顺序:router=>config=>shards 一,配置config: 3.4中config必须为replSet.下面配置两个config. ...

  3. selenium学习笔记(selenium下载安装)

    博主自己捣鼓的接口框架先到这里 等工作上正式开始使用再后续完善需求 还是继续学习python.学编程就直接动手写 就想看看python+selenium的组合 什么都不多说.先下载安装 博主这里已经安 ...

  4. spring3: 延迟初始化Bean

    3.3.1  延迟初始化Bean 延迟初始化也叫做惰性初始化,指不提前初始化Bean,而是只有在真正使用时才创建及初始化Bean. 配置方式很简单只需在<bean>标签上指定 “lazy- ...

  5. Appium 自动化测试(4)-- 脚本开发:官方demo演示 android_contacts.py

    前提:根据前面的环境搭建介绍,安装好相关环境 step1:启动android模拟器 step2:启动Appium服务端 step3:演示代码执行 这里执行的是官方的演示代码:通讯录管理app,安装打开 ...

  6. redis之linux下的安装

    安装 1.在/usr/local下新建redis文件夹 #mkdir redis 2.去redis.io下载redis安装包 # wget http://download.redis.io/relea ...

  7. linux命令三

    作业一:1) 将用户信息数据库文件和组信息数据库文件纵向合并为一个文件/1.txt(覆盖) [root@bogon test]# cat /etc/passwd /etc/group > /1. ...

  8. 【设计模式】calendar的单例需求和实现

    calendar单例需求: 参数:有default的calendar file 1.如果无实例,无参数调用,取default,检查是否合法,存入实例 2.如果无实例,有参数调用,检查是否合法,存入实例 ...

  9. ROS中使用ABB Yumi IRB14000的一些资料汇总

    目前,ABB RobotStudio 已经更新到6.05.01了,可至官网下载. 使用ABB RobotStudio和ROS进行联合调试,请参考下文: http://blog.csdn.net/Zha ...

  10. 前端之jQuery03 插件

    jQuery.fn.extend(object) 扩展 jQuery 元素集来提供新的方法(通常用来制作插件) 增加两个插件方法: // jQuery 扩展机制 // 自己扩展两个方法 // 把我这个 ...