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. mac开发环境搭建篇(2)--brew与mysql

    [brew]:参考 https://www.cnblogs.com/zoulifeng2017/p/7514139.html 安装brew: 终端执行:/usr/bin/ruby -e "$ ...

  2. Java反射、反射练习整理

    反射 JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意一个方法和属性:这种动态获取的信息以及动态调用对象的方法的功能称为java语 ...

  3. 浅谈js中的this关键字

    ---恢复内容开始--- this是JavaScript中的关键字之一,在编写程序的时候经常会用到,正确的理解和使用关键字this尤为重要.接下来,笔者就从作用域的角度粗谈下自己对this关键字的理解 ...

  4. 更换gcc工具链

    title: 更换gcc工具链 date: 2019/1/16 19:27:51 toc: true --- 更换gcc工具链 下载后解压到一个临时目录先看看文件结构 mkdir tmp tar xj ...

  5. 爬虫案例之Pubmed数据库下载

    代码 # encoding=utf-8 import os, time, re import urllib.request import urllib.parse import ssl ssl._cr ...

  6. 纯js Ajax 请求

    var XMLHttpReq; function createXMLHttpRequest() { if(window.ActiveXObject ) { try { XMLHttpReq = new ...

  7. jQuery使用(十三):工具方法

    proxy() onConflict() each() map() parseJson() makeArray() proxy() $.proxy()的实现机制与原生javaScript中的bind( ...

  8. nginx反向代理-解决前端跨域问题

    1.定义 跨域是指a页面想获取b页面资源,如果a.b页面的协议.域名.端口.子域名不同,所进行的访问行动都是跨域的,而浏览器为了安全问题一般都限制了跨域访问,也就是不允许跨域请求资源.注意:跨域限制访 ...

  9. Erdos

    Erdős Pál(1913年3月26日-1996年9月20日),匈牙利籍犹太人,发表论文达1475篇(包括和人合写的),为现时发表论文第二多的数学家(第一是Euler):曾和509人合写论文. Er ...

  10. Groovy 设计模式 -- 责任链模式

    Chain of Responsibility Pattern http://groovy-lang.org/design-patterns.html#_chain_of_responsibility ...