QOJ.ac

QOJ

実行時間制限: 4 s メモリ制限: 2048 MB 満点: 100

#2805. 梅森的标记

統計

石匠标记(Mason’s Mark)是建筑或其他公共结构中石料上常见的符号。当 Peter 带着相机走过巴黎时,他注意到了“无畏者让之塔”(Tour Jean-Sans-Peur)墙上的这些标记。每一块石头上都有 A、B 或 C 中的一个标记,这些标记清晰可见。他拍摄了一张黑白照片并观察到:

  • 照片展示了多块石头,每一块石头上恰好包含一个标记。
  • 所有标记的形状如下所示,其中 $x$ 和 $y$ 为任意严格正整数,且对于每个标记可能不同。注意,标记被白色像素包围,且标记不能旋转。
  • 照片中包含一些噪声,即被 8 个白色像素包围的黑色像素。
  • 存在 3 种黑色像素,分别对应噪声、石匠标记以及石头周围的区域。
  • 每个白色像素都属于某块石头的表面,其中一些也属于标记的内部。
  • 属于同一块石头表面但不属于标记内部的白色像素,在垂直和水平相邻关系上都是连通的。然而,石头的表面可能是非凸的。
  • 石头周围区域的黑色像素在垂直、水平、对角线和反对角线相邻关系上是连通的,这意味着你可以通过移动到八个相邻像素中的任意一个,从该区域的任何一个黑色像素到达该区域的任何其他黑色像素。图片边界上的所有像素均为黑色,且属于该区域。

给定一个表示 Peter 所拍照片的矩形矩阵。字符 '#' 代表黑色像素,字符 '.' 代表白色像素。你需要统计照片中带有 A、B 和 C 标记的石头各有多少块。

输入格式

第一行包含两个整数 $W$ 和 $H$。接下来的 $H$ 行,每行包含一个长度为 $W$ 的字符串。字符串由 '.' 和 '#' 组成。

数据范围

  • $7 \le W \le 1000$
  • $9 \le H \le 1000$

输出格式

输出一行,包含三个由空格分隔的整数 $A$、$B$ 和 $C$,分别表示带有 A、B 和 C 标记的石头的数量。

样例

输入格式 1

26 15
##########################
##........######......#..#
#...###....#####..#......#
#...#.#....####.........##
#...###.....##....#####..#
#...#.#.....#.....#####..#
#...###.....#.....##.##..#
#........#..#.#...#####..#
#..###......#.....#####..#
#..#........#...#.##.##..#
#..#........#.....##.##..#
#..#...#.#..#...#.##.##..#
#..###......#............#
###....#....##....##.....#
##########################

输出格式 1

1 1 0

说明

图中存在形成字母 C 的黑色像素。然而,这些像素属于石头周围的区域,并不构成一个标记,因为它们没有被白色像素包围。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.