Problem Description
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×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.

 
Input
The first line is an integer T which represents the case number.
As for each case, the first line are two integers n and m , which are the height and the width of the photo.
Then there are n lines followed, and there are m characters of each line, which are the the details of the photo.It is guaranteed that:
T is about 50.
1≤n≤1000 .
1≤m≤1000 .
∑(n×m)≤2×106.
 Output
As 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<cstdio>
#include<iostream>
using namespace std;
const int N=;
int dir[][]={{,},{,-},{,},{-,}};
char girl[]="girl";
char cat[]="cat";
char map[N][N];
int n,m,sumg,sumc;
void dfsgirl(int i,int j,int cnt)
{
if(i<||j<||i>=n||j>=m)
return;
else{
if(map[i][j]==girl[cnt]){
if(cnt==){
sumg++;
return;
}
dfsgirl(i-,j,cnt+);
dfsgirl(i,j-,cnt+);
dfsgirl(i+,j,cnt+);
dfsgirl(i,j+,cnt+);
}
}
return;
}
void dfscat(int i,int j,int cnt)
{
if(i<||j<||i>=n||j>=m)
return;
else{
if(map[i][j]==cat[cnt]){
if(cnt==){
sumc++;
return;
}
dfscat(i-,j,cnt+);
dfscat(i,j-,cnt+);
dfscat(i+,j,cnt+);
dfscat(i,j+,cnt+);
}
}
return;
}
int main()
{
int t;scanf("%d",&t);
while(t--){
sumg=,sumc=;
scanf("%d%d",&n,&m);
for(int i=;i<n;i++){
scanf("%s",map[i]);
}
for(int i=;i<n;i++){
for(int j=;j<m;j++){
if(map[i][j]=='g'){
dfsgirl(i,j,);
}
if(map[i][j]=='c'){
dfscat(i,j,);
}
}
}
printf("%d %d\n",sumg,sumc);
}
return ;
}

hdu5706-GirlCat的更多相关文章

  1. 2016女生专场 ABCDEF题解 其他待补...

    GHIJ待补... A.HUD5702:Solving Order Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/3276 ...

  2. HDU-5706

    GirlCat Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Problem Desc ...

  3. HDU 5706 GirlCat (DFS,暴力)

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

  4. hdu 5706 GirlCat(BFS)

    As a cute girl, Kotori likes playing ``Hide and Seek'' with cats particularly. Under the influence o ...

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

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

随机推荐

  1. Django+Vue打造购物网站(十一)

    第三方登录 微博创建应用,修改回调地址 http://open.weibo.com/authentication 安装第三方登录插件 https://github.com/python-social- ...

  2. usb驱动程序小结(六)

    title: usb驱动程序小结 tags: linux date: 2018/12/20/ 17:59:51 toc: true --- usb驱动程序小结 linux中为usb驱动也提供了一套总线 ...

  3. Mac 终端美化方法

    美化终端,主要是主题,字体,命令行提示3个方面. 主题 使用的主题是Solarized Dark主题. 安装主题: git clone git://github.com/altercation/sol ...

  4. 第十二节: EF的三种模式(二) 之 ModelFirst模式(SQLServer为例)

    一. 简介  顾名思义,ModelFirst是模型优先,是DBFirst的逆向模式,先建立实体数据模型,然后根据实体数据模型来生成数据库,从而驱动整个开发流程.(生成一个空的edmx文件,手动在里面建 ...

  5. 使用HttpClient和WebRequest时POST一个对象的写法

    [一]步骤: 1)将对象转化为Json字符串. 2)将Json字符串编码为byte数组. 3)设置传输对象(WebRequest或者HttpClient)的ContentType是"appl ...

  6. 软件测试之adb命令-实际公司使用场景--今日log

    软件测试之adb命令-实际公司使用场景--今日log Dotest-董浩整理 1)可以看内存泄漏: 2)可以安装.卸载app--截图并提交bug: 3)可以通过抓app日志定位问题: 4)可以结合mo ...

  7. 「luogu3313」[SDOI2014] 旅行

    题目大意 :有 n 个城市连成一棵树, 每个城市有两个关键字, 一个是该城市的宗教, 另一个是城市的评级;旅行者要在城市间旅行, 他只会在和自己宗教相同的城市留宿;维护四个树上操作 { 1. “CC ...

  8. Linux 首先基本包安装(vim啊什么的),源,源优化,项目架构介绍, (LNMuWsgi)Django项目相关软件mysql,redies,python(相关模块)安装配置测试

    内容 补充: 查看已启动服务的端口 netstat -tulnp |grep (方式1) ss -tulnp|grep (方式2) 前期铺垫: . Linux要能上网 . 掌握Linux软件包安装方法 ...

  9. 使用fiddler模拟重复请求接口

    使用fiddler模拟重复请求接口 重复请求某个接口,比如评论一条,这样点击多次就可以造多个评论数据

  10. NYOJ

    爬行的蚂蚁 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 有N只蚂蚁以每秒1cm的速度在长为Lcm的竿子上爬行.当蚂蚁爬到竿子的端点时就会掉落.由于竿子太细,两只蚂 ...