单点时限: 1.0 sec
内存限制: 128 MB
给你一些黑白图片,每张图片只会包含大写字母A
、B
、C
。请你编写一个程序,识别出每张图片中A
、B
、C
分别有几个。
有多组测试数据。在每组测试数据中,第一行包含两个整数 $N,M(0 < N, M \leq 200)$,表示图片的分辨率为 $N$ 行 $M$ 列。接下来有 $N$ 行,每行包含 $M$ 个像素。#
代表黑色像素,.
代表白色像素。
每个字母都由黑色像素组成,这些像素通过顶部、底部、左侧、右侧连接在一起。字母可以拉伸和旋转,但是不能撕裂。字母不会重叠,不会相互包含。每个黑色像素都属于一个字母。对角接触的两个黑色像素一定会有共同接触的黑色像素。
提示:可以根据白洞来识别字母。A
有一个白洞,B
有两个白洞,C
没有白洞。
对于每组测试数据,分别输出A
、B
、C
的数量。
25 60 ............................................................ ............................................................ ...........................#####............................ ..........................#######........................... .........................#########.......................... ........................####...####......................... .......................####....#####........................ ......................###############....................... .....................#################...................... ....................####..........#####..................... ...................#####...........#####.................... ............................................................ ............................................................ ............................................................ ......##############....................##########.......... ......####.......#####...............#####......#####....... ......####........#####............#####.........#####...... ......####......######............#####..................... ......###############.............#####..................... ......####.........####............####..................... ......####.........#####...........####...........####...... ......####........#####.............######......#####....... ......################................#############......... ............................................................ ............................................................ 25 60 ............................................................ ............................................................ ............................................................ ...##.................................................##.... ...#######.......................................#######.... ........##########.......................###########........ ..........##############............#############........... ..........####........#####.....######.......####........... ..........####..##########......##########...####........... ........##########......................##########.......... ...##########................................###########.... ...###...............................................###.... ............................................................ ............................................................ ............................................................ ..................########################.................. ..................########################.................. ..................####.......####.....####.................. ..................####.......####.....####.................. ..................####.......####....####................... ...................#####...##############................... ......................#######............................... ............................................................ ............................................................ ............................................................
1 1 1 2 1 0