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. Python Installing Jupyter

    Jupyter说明jupyter notebook是一款网页版的Python编辑器组件,便于学习Python Jupyer安装yum -y install gcc gcc-c++ kernel-dev ...

  2. rt-thread 之组件与设备初始化配置

    @2019-03-08 [小记] rt-thread 初始化配置有两个分支: 第一,板级设备初始化 rt_components_board_init() 第二,内核组件初始化 rt_component ...

  3. 前端ajax请求百度地图api

    $.ajax({ type: "get", url: 'http://api.map.baidu.com/place/v2/search', data:{ ak:'您的ak', q ...

  4. selenium技术博客

    1.java+selenium+详细的api说明和seleniumGrid使用,缺点是代码不够好看. http://www.cnblogs.com/yytesting/p/5714175.html

  5. Harbo1.5.2离线搭建

    环境说明 操作系统版本:Centos7.5 docker版本:docker-ce 17.03.2 harbor版本:v1.5.2 docker-compose:  1.22.0 基础环境搭建 系统优化 ...

  6. 如何给pdf文件中的一页添加水印

    如题所述,项目需求.要把一份文件尾部加上签章,首先想到的就是水印. 开始试过了无论是word还是wps所谓的水印其实就是页脚或页眉统一格式,无法单一一个页面操作,要加所有的页面都有. 纵然wps有个功 ...

  7. LeetCode 92. ReverseLinkedII

    #include <iostream> using namespace std; struct ListNode { int val; ListNode *next; ListNode(i ...

  8. vsftpd启动问题简记

    centos7 能以ipv6方式启动,启动只需修改配置如下 如需同时启动到ipv4跟ipv6,需拷贝配置文件,一份配置中只监听ipv4,一份配置中只监听ipv6 centos6中无法启动到ipv6,错 ...

  9. 设 $y_1(x), y_2(x)$ 是 $y''+p(x)y'+q(x)y=0$ 的两个解 ($p(x), q(x)$ 连续), 且 $y_1(x_0)=y_2(x_0)=0$, $y_1(x)\not\equiv 0$. 试证: $y_1(x)$, $y_2(x)$ 线性相关.

    设 $y_1(x), y_2(x)$ 是 $y''+p(x)y'+q(x)y=0$ 的两个解 ($p(x), q(x)$ 连续), 且 $y_1(x_0)=y_2(x_0)=0$, $y_1(x)\n ...

  10. [数学笔记Mathematical Notes]1-调和级数发散的一个简单证明

    定理. 调和级数 $\dps{\vsm{n}\frac{1}{n}}$ 是发散的. 证明. 设 $$\bex a_n=\sum_{k=1}^n\frac{1}{k}, \eex$$ 则 $a_n$ 递 ...