hdu5706-GirlCat
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.
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.
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
1 4
girl
2 3
oto
cat
3 4
girl
hrlt
hlca
思路:给你一个二维字符串,可以看成图;再给两个子串“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的更多相关文章
- 2016女生专场 ABCDEF题解 其他待补...
GHIJ待补... A.HUD5702:Solving Order Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/3276 ...
- HDU-5706
GirlCat Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Problem Desc ...
- HDU 5706 GirlCat (DFS,暴力)
题意:给定一个n*m的矩阵,然后问你里面存在“girl”和“cat”的数量. 析:很简单么,就是普通搜索DFS,很少量.只要每一个字符对上就好,否则就结束. 代码如下: #include <cs ...
- hdu 5706 GirlCat(BFS)
As a cute girl, Kotori likes playing ``Hide and Seek'' with cats particularly. Under the influence o ...
- HDU - 5706 - Girlcat - 简单搜索 - 新手都可以看懂的详解
原题链接: 大致题意:给你一个二维字符串,可以看成图:再给两个子串“girl”和“cat”,求图中任意起点开始的不间断连接起来的字母构成的两个子串的分别的个数:连接的方向只有不间断的上下左右. 搜索函 ...
随机推荐
- redis源码解析(1):redisObject对象说明
Redis在实现键值对数据库时,并没有直接使用数据结构,而是基于已有的数据结构创建了一个对象系统,每种对象至少包含一种数据结构. redis3.0 中对象结构: typedef struct redi ...
- JQuery 的遍历方法 $.each
博主呢最近在公司实习,发现公司基本上都会统一代码风格,今天看到还有很多事用JQuery写的js 请求Ajax与后台进行数据交互的方式 当我看到$each 遍历时 然我想起我学JQuery的时候 于是复 ...
- MongoDB 3.6.9 集群搭建 - 切片+副本集
1. 环境准备 在Mongo的官网下载Linux版本安装包,然后解压到对应的目录下:由于资源有限,我们采用Replica Sets + Sharding方式来配置高可用.结构图如下所示: 这里我说明下 ...
- 第五节:WebApi的三大过滤器
一. 基本说明 1. 简介: WebApi下的过滤器和MVC下的过滤器有一些区别,首先我们要注意的是通常建WebApi项目时,会自动把MVC的程序集也引入进来,所以我们在使用WebApi下的过滤器的 ...
- django - 总结
0.html-socket import socket def handle_request(client): request_data = client.recv(1024) print(" ...
- [物理学与PDEs]第5章习题5 超弹性材料中客观性假设的贮能函数表达
设超弹性材料的贮能函数 $\hat W$ 满足 (4. 19) 式, 证明由它决定的 Cauchy 应力张量 ${\bf T}$ 满足各向同性假设 (4. 7) 式. 证明: 若贮能函数 $W$ 满足 ...
- 🍓 DOM常用基础知识点汇总(入门者适用) 🍓
铛-今天又没啥事,来总结一下DOM的基础知识.(公司没活干我也很无奈
- XXE漏洞学习
0x00 什么是XML 1.定义 XML用于标记电子文件使其具有结构性的标记语言,可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进行定义的源语言.XML文档结构包括XML声明.DTD文 ...
- 【原创】大叔问题定位分享(14)Kylin频繁OOM问题
公司一个kylin集群,每到周二下午就会逐个节点OOM退出,非常有规律,kylin集群5个节点,每个节点分配的内存已经不断增加到70多G,但是问题依旧: 经排查发现,每周二下午kylin集群的请求量确 ...
- Java_日期时间相关类
目录 Date类(java.util.date) Calendar类(java.util.Calendar) SimpleDateFormat类(java.text.SimpleDateFormat) ...