hdoj-5706-GirlCat
来源:互联网 发布:淘宝过户服务费 编辑:程序博客网 时间:2024/04/30 08:36
Problem Description
As a cute girl, Kotori likes playing Hide and Seek'' with cats particularly.
Hide and Seek” together.
Under the influence of Kotori, many girls and cats are playing
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.
cat” 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
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
简单的dfs,要求连续的cat和girl的个数,然后四个方向搜一搜
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#define exp 1e-10using namespace std;const int N = 1005;const int M = 15;const int inf = 100000000;const int mod = 2009;char s[N][N],ch[2][5]={"girl","cat"};bool v[N][N];int ans[2],n,m;bool check(int x,int y){ return x>=0&&x<n&&y>=0&&y<m;}void dfs(int x,int y,int k,int t){ if(!check(x,y)||s[x][y]!=ch[t][k]) return; v[x][y]=true; if(t&&k==2||!t&&k==3) { ans[t]++; return; } dfs(x+1,y,k+1,t); dfs(x,y+1,k+1,t); dfs(x-1,y,k+1,t); dfs(x,y-1,k+1,t);}int main(){ int t; scanf("%d",&t); while(t--) { ans[0]=ans[1]=0; memset(v,false,sizeof(v)); scanf("%d%d",&n,&m); for(int i=0;i<n;i++) scanf("%s",s[i]); for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(!v[i][j]) { if(s[i][j]=='g') dfs(i,j,0,0); else if(s[i][j]=='c') dfs(i,j,0,1); } printf("%d %d\n",ans[0],ans[1]); } return 0;}
- hdoj-5706-GirlCat
- hdu 5706 GirlCat(dfs)
- hdu 5706 GirlCat(深搜)
- 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女生专场】
- DFS-GirlCat
- HDU5706 GirlCat
- HDU5706 GirlCat(简单dfs)
- 2016女生赛 1005 GirlCat【DFS】
- HDOJ
- hdoj
- hdoj
- android 学习笔记十二 监听键盘状态
- ios项目中安装和使用CocoaPods
- Valid Anagram (java)
- Ubuntu15 安装Pycharm
- 我的第一个Linux小程序(进度条)
- hdoj-5706-GirlCat
- Java集合接口
- iOS -- CALayer之锚点
- Keras学习笔记1——win7__keras框架搭建步骤(Theano)
- Linux命令-df、du
- CFRunLoop
- oracle 导出导入不含数据的空库
- Thread类的使用
- 基于SIM900A-GPRS模块的远程文件传输实例