5109. ABC

单点时限: 1.0 sec

内存限制: 128 MB

给你一些黑白图片,每张图片只会包含大写字母ABC。请你编写一个程序,识别出每张图片中ABC 分别有几个。

输入格式

有多组测试数据。在每组测试数据中,第一行包含两个整数 $N,M(0 < N, M \leq 200)$,表示图片的分辨率为 $N$ 行 $M$ 列。接下来有 $N$ 行,每行包含 $M$ 个像素。#代表黑色像素,.代表白色像素。

每个字母都由黑色像素组成,这些像素通过顶部、底部、左侧、右侧连接在一起。字母可以拉伸和旋转,但是不能撕裂。字母不会重叠,不会相互包含。每个黑色像素都属于一个字母。对角接触的两个黑色像素一定会有共同接触的黑色像素。

提示:可以根据白洞来识别字母。A有一个白洞,B有两个白洞,C没有白洞。

输出格式

对于每组测试数据,分别输出ABC的数量。

样例

Input
25 60
............................................................
............................................................
...........................#####............................
..........................#######...........................
.........................#########..........................
........................####...####.........................
.......................####....#####........................
......................###############.......................
.....................#################......................
....................####..........#####.....................
...................#####...........#####....................
............................................................
............................................................
............................................................
......##############....................##########..........
......####.......#####...............#####......#####.......
......####........#####............#####.........#####......
......####......######............#####.....................
......###############.............#####.....................
......####.........####............####.....................
......####.........#####...........####...........####......
......####........#####.............######......#####.......
......################................#############.........
............................................................
............................................................
25 60
............................................................
............................................................
............................................................
...##.................................................##....
...#######.......................................#######....
........##########.......................###########........
..........##############............#############...........
..........####........#####.....######.......####...........
..........####..##########......##########...####...........
........##########......................##########..........
...##########................................###########....
...###...............................................###....
............................................................
............................................................
............................................................
..................########################..................
..................########################..................
..................####.......####.....####..................
..................####.......####.....####..................
..................####.......####....####...................
...................#####...##############...................
......................#######...............................
............................................................
............................................................
............................................................
Output
1 1 1
2 1 0

100 人解决,108 人已尝试。

111 份提交通过,共有 197 份提交。

2.3 EMB 奖励。

创建: 1 年,6 月前.

修改: 1 年,6 月前.

最后提交: 8 月前.

来源: N/A

题目标签