C.S.I.: P15
InterviewTime limit1sMemory limit256 MB
Count ground-connected 8-connected flower components and isolated /\/\ bird patterns in each ASCII picture.
- Level
Medium4 of 10
- Topics
- DFS, String matching
- Solved
- No attempts yet
Problem
You have been cast as the computer genius who cracks the case in the season finale of C.S.I.: P15. As expected, a camera feed shows up that needs to be analyzed. The camera records in HD-9000 quality with extra regression, the stream is then matched inside the camera by a re-inverted isomorphic bit coefficient matrix and plasma shifted five times for good measure. You view the feed through Netscape Navigator 4 Platinum Edition.
The trouble is that a saboteur switched the camera into ASCII mode and into picture burst mode. All you have left is a pile of still ASCII images. For reasons the show reveals later, you have to design and implement a deterministic algorithm that counts the flowers and the birds in one still image.
The rules of an image are these.
- Air is a
.(a dot). - The ground is the last line of the image and holds
=characters only. Nothing else ever appears on that line. - Two cells are 8-connected when they share an edge or a corner.
- A flower is an 8-connected component of cells taken from
|,/,\,-,@that is connected to the ground. A component is connected to the ground when one of its cells is 8-adjacent to a=cell of the last line. - A bird is an occurrence of
/\/\inside a single line whose four cells are surrounded exclusively by air, or by the edges of the image.
So something that looks like a bird but sits on the ground is a flower. It may be an ex-parrot, but here it counts as a flower too.
Input
The first line holds one integer , the number of test cases. Each test case begins with a line of two integers separated by a space, the height and the width , and continues with lines describing the picture. Each line of the picture has exactly characters. All lines but the last consist of ., |, /, \, -, @ only, and the last line consists of = only.
Output
For each test case, print two lines. If the number of flowers is and the number of birds is , print
Flowers: F
Birds: B