QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 100

#2955. 稳定桌子

统计

先锋派木匠 Mort S. Tenon 擅长用形状各异的木块组装家具。利用强力胶、巧妙隐藏的配重和地面锚固件,Tenon 可以制作出看起来违背重力的桌子,如图 1(b) 所示。他首先创建一个由木块组成的矩形块,这些木块的垂直横截面是直线多边形,即边要么是水平的,要么是垂直的多边形。其中一些木块可能包含其他木块的孔洞。然后,他尽可能多地移除木块,留下一个由最少数量的稳定木块组成的结构,且该结构必须包含矩形块的整个顶面。出于美观原因(与木纹图案有关),Mort 制作的桌子顶面最多只能由两块木块组成。

图 1(a) 展示了带有切割痕迹的初始矩形块。通过移除编号为 1 和 2、4 到 7 以及 11 和 12 的木块,他制作出了图 1(b) 所示的稳定桌子。如果一个木块要么直接与地面接触,要么其至少有一条水平边位于另一个稳定木块的水平边之上并与之接触,则该木块被认为是稳定的。两个相邻木块之间的接触区域必须具有正面积,接触才算稳定;仅沿角接触是不够的。

图 K.1:样例输入 1 的说明

给定初始木块的描述,请帮助 Mort 确定一个包含最少木块数量的稳定桌子。

输入格式

输入的第一行包含两个正整数 $h$ 和 $w$ ($1 \le h, w \le 100$),表示初始木块块的高度和宽度。接下来的 $h$ 行,每行包含 $w$ 个正整数,描述了块中每个 $1 \times 1$ 单位所关联的木块编号。所有木块的编号从 1 到块中木块的总数,且各不相同。由于输入的第一行最多包含两个木块编号,因此最多有 9902 个木块。木块可能包含有孔洞,孔洞中包含其他木块;每个木块通过组成该木块的 $1 \times 1$ 单位之间的共享边连接。

输出格式

输出一个整数,表示稳定桌子中最少需要的木块数量。

样例

输入 1

8 12
13 13 13 13 13 13 13 13 3 3 3 3
13 13 13 13 13 13 13 13 3 2 2 3
13 13 13 1 1 13 13 13 3 3 3 3
13 13 13 1 1 13 13 13 8 11 11 11
13 13 13 13 13 7 8 8 8 11 11 11
13 13 13 13 13 7 9 9 9 11 11 11
4 4 4 4 6 6 10 10 10 11 12 12
5 5 5 5 6 6 10 12 12 12 12 12

输出 1

5

输入 2

3 4
8 8 8 8
5 6 7 8
1 2 3 4

输出 2

2

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.