HDU
来源:互联网 发布:手机小说码字软件 编辑:程序博客网 时间:2024/06/16 07:08
GirlCat
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1020 Accepted Submission(s): 642
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 is n\times 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 n\times 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.
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\leq n\leq 1000.
1\leq m\leq 1000.
\sum (n\times m)\leq 2\times 10^6.
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\leq n\leq 1000.
1\leq m\leq 1000.
\sum (n\times m)\leq 2\times 10^6.
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
"巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场
Recommend
liuyiding
题意:给一个 n * m 的矩阵,问其中有多少个 "girl" 和 "cat"
#include <bits/stdc++.h>using namespace std;int t, n, m;char a[1003][1003];int ans1, ans2;int dx[] = {0, 0, 1, -1};int dy[] = {1, -1, 0, 0};int dfs(int i, int j, int k, int f){ for(int t = 0; t < 4; t++){ int ii = i + dx[t]; int jj = j + dy[t]; if(ii >= 0 &&ii < n && jj >= 0 && jj < m){ if(f){ if(k == 1 && a[ii][jj] == 'i'){ dfs(ii, jj, 2, f); } if(k == 2 && a[ii][jj] == 'r'){ dfs(ii, jj, 3, f); } if(k == 3&& a[ii][jj] == 'l'){ ans1++; } } else { if(k == 1 && a[ii][jj] == 'a'){ dfs(ii, jj, 2, f); } if(k == 2 && a[ii][jj] == 't'){ ans2++; } } } }}int main(){ scanf("%d", &t); while(t--){ scanf("%d%d", &n, &m); for(int i = 0; i < n; i++){ scanf("%s", a[i]); } ans1 = 0, ans2 = 0; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ if(a[i][j] == 'g'){ dfs(i, j, 1, 1); } if(a[i][j] == 'c'){ dfs(i, j, 1, 0); } } } printf("%d %d\n", ans1, ans2); }}
阅读全文
0 0