E
来源:互联网 发布:设计展板用什么软件 编辑:程序博客网 时间:2024/04/29 07:45
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.
As for each case, the first line are two integers
Then there are
It is guaranteed that:
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.
31 4girl2 3otocat3 4girlhrlthlca
1 00 24 1
题意:
找矩阵里有几个girl和cat,其中只要有一个点不一样的话这两个女孩(cat)就是不一样的。
思路:搜索dfs
代码:
#include <iostream>#include<stdio.h>#include<cstdio>#include<iostream>#include<algorithm>#include<math.h>#include<string.h>#include<map>#include<queue>#include<vector>#include<deque>#define ll long long#define inf 0x3f3f3f3f#define mem(a,b) memset(a,b,sizeof(a))using namespace std;int dir[4][2]= {{0,1},{1,0},{-1,0},{0,-1}};char a[2][10]= {"cat","girl"};char mp[1001][1001];int n,m;int sum,sum1;void dfs(int x,int y,int flag,int k)//用flag=1,0来判断是cat还是girl。{ if(flag==1) { if(k==3) { sum++; return; } } if(flag==0) { if(k==2) { sum1++; return; } } for(int i=0; i<4; i++) { int xx=x+dir[i][0]; int yy=y+dir[i][1]; if(mp[xx][yy]==a[flag][k+1]&&xx>=0&&xx<n&&yy>=0&&yy<m)//定义一个数组cat,girl每次和之后的一个字母一样就继续往后搜 { dfs(xx,yy,flag,k+1); } }}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); //getchar(); sum=0;sum1=0; for(int i=0; i<n; i++) { scanf("%s",mp[i]); } int x,y,x1,y1; for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { if(mp[i][j]=='g') { dfs(i,j,1,0); } if(mp[i][j]=='c') { dfs(i,j,0,0); } } } printf("%d %d\n",sum,sum1); }}
0 0
- e
- E
- E
- e
- e
- e
- e
- e
- E
- e
- E
- e
- e
- E
- e
- e
- e
- E
- 常用sql语句
- 动态规划练习--13(最大上升子序列和)
- leetcode---Arithmetic Slices
- java AWT记事本
- 类延迟加载
- E
- Swing触发事件的3种方法
- The KITTI Vision Benchmark Suite之Semi-Convex Hull for Mesh Simplification
- css选择器的种类
- 把数组排成最小的数
- Linux
- 二叉树的层次遍历
- OpenCV1-读写图片,使用Matplotlib
- 剑指offer2.3.2字符串:有两个排序的数组A1和A2,内存在A1的末尾有足够多的空余空间容纳A2,编写一个函数,将A2合并到A1并排序