hdu 5706 GirlCat(深搜)
来源:互联网 发布:is淘宝刷单兼职靠谱吗 编辑:程序博客网 时间:2024/05/17 07:44
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5706
GirlCat
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 132 Accepted Submission(s): 104
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 isn×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.
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
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 integersn and m , which are the height and the width of the photo.
Then there aren 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 .
As for each case, the first line are two integers
Then there are
It is guaranteed that:
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.
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
31 4girl2 3otocat3 4girlhrlthlca
Sample Output
1 00 24 1
Source
"巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场
解题思路:找到一个起始点,直接进行搜索,查找接下去的字母。
详见代码。
#include <iostream>#include <cstdio>using namespace std;char Map[1010][1010];char ans[2][10]= {{"cat"},{"girl"}};int dir[4][2]= {0,1,0,-1,1,0,-1,0}; //4行2列int n,m,s1,s2;void dfs(int x,int y,int flag,int num)//flag用来标记我当前找的字符串是cat还是girl,num用来表示当前找到了是第几个字符。{ if (flag==1)//girl { if (num==3)//找到了girl的长度就加加 { s1++; return; } for (int i=0; i<4; i++) { int X=x+dir[i][0]; int Y=y+dir[i][1]; if (X>=0&&X<n&&Y>=0&&Y<m&&(Map[X][Y]==ans[flag][num+1]))//一个字符一个字符比较,看是否为我接下去要找的那个字符 { dfs(X,Y,1,num+1); } } } if (flag==0) { if (num==2) { s2++; return; } for (int i=0; i<4; i++) { int X=x+dir[i][0]; int Y=y+dir[i][1]; if (X>=0&&X<n&&Y>=0&&Y<m&&(Map[X][Y]==ans[flag][num+1])) { dfs(X,Y,0,num+1); } } }}int main(){ int t; scanf("%d",&t); while (t--) { s1=s2=0; scanf("%d%d",&n,&m); for (int i=0; i<n; i++) { scanf("%s",Map[i]); } for (int i=0; i<n; i++) { for (int j=0; j<m; j++) { if (Map[i][j]=='g') dfs(i,j,1,0); if (Map[i][j]=='c') dfs(i,j,0,0); } } printf ("%d %d\n",s1,s2); } return 0;}
0 0
- hdu 5706 GirlCat(深搜)
- hdu 5706 GirlCat(dfs)
- HDU 5706 GirlCat
- hdu 5706 GirlCat
- hdu 5706 GirlCat(DFS)
- hdu 5706 GirlCat
- hdu 5706 GirlCat 暴力
- hdu 5706 GirlCat【暴力DFS】
- HDU 5706 GirlCat DFS解决
- HDU-5706-GirlCat【BFS】【2016CCPC女生专场】
- hdoj-5706-GirlCat
- DFS-GirlCat
- HDU5706 GirlCat
- HDU5706 GirlCat(简单dfs)
- 2016女生赛 1005 GirlCat【DFS】
- 【2016杭电女生赛1005】【暴力 bfs or dfs or 模拟】girlcat 数女生数和猫咪数
- HDU 5706 暴力dfs
- hdu 1010 深搜+回溯
- win7 Just-install让你一键部署百余款热门应用程序
- 8.Oracle索引
- indeed contenst
- 面向对象9
- 写给VR手游开发小白的教程:(一)Unity3D进行Android开发的环境搭建(虚拟机调试)
- hdu 5706 GirlCat(深搜)
- MBProgressHUD、SVProgressHUD基本使用方法
- javaScript--01 HTML 下 JavaScript简介
- 9.Oracle分区表
- 专访李智慧:架构是最高层次的规划和难以改变的决定
- 安装配置JDK1.7
- Maven学习总结(21)——Maven常用的几个核心概念
- 10.1OraclePL_SQL基础&变量声明
- CountDownLatch、CyclicBarrier和Semaphore