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”,求图中任意起点开始的不间断连接起来的字母构成的两个子串的分别的个数:连接的方向只有不间断的上下左右. 搜索函 ...
随机推荐
- 学习Spring Boot:(十五)使用Lombok来优雅的编码
前言 Lombok 是一种 Java™ 实用工具,可用来帮助开发人员消除 Java 的冗长,尤其是对于简单的 Java 对象(POJO).它通过注解实现这一目的. 正文 添加依赖 在 pom.xml ...
- VirtualBox下安装linux虚拟机
下载VirtualBox 下载地址:https://www.virtualbox.org/wiki/Downloads 安装VirtualBox 安装虚拟机 如果选择不到64位系统, 开机按 F1 进 ...
- MySQL安装-二进制软件包安装
MySQL 双版本安装 安装mysql AB (RPM) -mysql官方的RPM包 安装MySQL 5.6.19版本 安装之前需要将系统自带的关于mysql软件全部卸载掉 rpm -e (加 ...
- Java多线程编程-线程之间的通信
转载自:这里 学习了基础的线程知识 看到了 线程之间的通信 线程之间有哪些通信方式呢? 1.同步 这里讲的同步是指多个线程通过synchronized关键字这种方式来实现线程间的通信. public ...
- 礼物(中国剩余定理+拓展gcd求逆元+分治=拓展Lucus)
礼物 题意: 求\[C(n,m)\ \%\ p\] \(n,m,p\le 10^9\),且若\(p=\prod_{i=1}^{k}{p_i}^{c_i}\),则\(\forall i\in [1..k ...
- mysql 重启,修改编码utf8mb4,并修改数据库链接,生效
1.启动:/etc/init.d/mysql start 2.停止:/etc/init.d/mysql stop 3.重启:/etc/init.d/mysql restart SHOW VARIABL ...
- Linux Centos7.x下安装部署Jira和confluence以及破解方法详述
简述 JIRA是Atlassian公司出品的项目与事务跟踪工具,被广泛应用于缺陷跟踪.客户服务.需求收集.流程审批.任务跟踪.项目跟踪和敏捷管理等工作领域. Confluence是一个专业的企业知识管 ...
- 【SQL】INSERT INTO SELECT语句与SELECT INTO FROM语句
INSERT INTO SELECT语句与SELECT INTO FROM语句,都是将一个结果集插入到一个表中: #INSERT INTO SELECT语句 1.语法形式: Insert into T ...
- LFYZ-OJ ID: 1026 数的计数(数的计算)NOIP2001
数的计算(数的计数) 题目描述 我们要求找出具有下列性质数的个数(包含输入的自然数n).先输入一个自然数n(n<=1000),然后对此自然数按照如下方法进行处理: 不作任何处理; 在它的左边加上 ...
- JavaScript null和undefined的区别
前言 1995年javascript诞生时,最初像Java一样,只设置了null作为表示"无"的值.根据C语言的传统,null被设计成可以自动转为0 但是,javascript的设 ...