Hdu-5706-girlcat "BFS" "2016CCPC Girls ' Session"

Source: Internet
Author: User

Hdu-5706-girlcat

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 are nxm, each pixel of the photo are a character of the lowercase (from a‘ to z ').
Kotori wants to know what many girls and how many cats is 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 C Haracters is 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 the cats is different if there was at least a point of the the the the and the Cats are different.

The points is regarded to is connected if and only if they share a common edge.

Input
The first line is a integer T which represents the case number.

As for each case, the first line is integers n and m, which is the height and the width of the photo.
Then there is n lines followed, and there is m characters of each line, which is the the details of the photo.

It's Guaranteed that:
T is about 50.
1≤n≤1000.
1≤m≤1000.
∑ (NXM) ≤2x106.

Output
As for each case, you need to output a.
There should is 2 integers in the line with a blank between them representing the number of girls and cats respectively.

Please make sure this 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

Title Link: HDU-5706

The main topic:, to find out the figure is exactly equal to ' girl ' and ' cat ' there are several.

Note
1. Must be completely equal to ' girl ' and ' cat '
2. The order cannot be reversed

Topic Idea: BFS, take girl as an example, find G to BFS, next equals I put into the queue, to this, see the last queue inside there are several L, is the answer

This problem, the game when the wrong title, thought as long as the girl or IRL, alone I can also. Kind of a girl. The code is very complicated to understand the end of the late, although a, but no time to write other topics, it feels good pity.

Here's the code:

////5706.cpp//2016-ccpc-girl////Created by Pro on 16/7/3.//Copyright (c) 2016 Loy. All rights reserved.//#include <iostream>#include <cstdio>#include <cmath>#include <vector>#include <cstring>#include <algorithm>#include <string>#include <set>#include <functional>#include <numeric>#include <sstream>#include <stack>#include <map>#include <queue>#include <iomanip>using namespace STD;intN,m;strings[1005];intvis[1005][1005]; Map <Char,char>mpintdx[5] = {1,-1,0,0};intdy[5] = {0,0,1,-1};structnode{CharChintx, y;};intAns_girl,ans_cat;voidBFsintRintCCharCH) { queue <node>Que//Head nodeNode Zero; zero.x = R; ZERO.Y = C;    zero.ch = ch; Que.push (zero); while(!que.empty ())        {Node front = Que.front ();        Que.pop (); VIS[FRONT.X][FRONT.Y] =1;if(front.ch = =' l ') {ans_girl++;Continue; }if(front.ch = =' t ') {ans_cat++;Continue; } for(inti =0; I <4; i++) {intx = dx[i] + front.x;inty = dy[i] + front.y;if(X <0|| X >= N | | Y <0|| Y >= m)Continue;//out of range            if(S[x][y]! = mp[front.ch])Continue;//Not the nextnode tmp; tmp.x = x; Tmp.y = y;            tmp.ch = S[x][y];        Que.push (TMP); }    }}intMain () {intTCin>> T; mp[' G '] =' I '; mp[' I '] =' R '; mp[' R '] =' l '; mp[' C '] =' A '; mp[' A '] =' t '; while(t--) {//Initialize        memset(Vis,0,sizeof(VIS)); Ans_girl =0; Ans_cat =0;Cin>> n >> m; for(inti =0; I < n; i++)Cin>> S[i]; for(inti =0; I < n; i++) { for(intj =0; J < M; J + +) {if(!vis[i][j] && s[i][j] = =' G '|| S[I][J] = =' C ') {BFS (i,j,s[i][j]); }            }        }cout<< Ans_girl <<" "<< Ans_cat << Endl; }return 0;}

Hdu-5706-girlcat "BFS" "2016CCPC Girls ' Session"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.