QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 512 MB Points totaux : 100

#16091. 山峰

Statistiques

你最近开始在荷兰最大的地图绘制公司工作。你的部分工作是确定特定地形中的山峰(summits)。不幸的是,确定哪些点是山峰、哪些不是并不那么容易,因为我们不想把一个小土丘也称为山峰。例如,看一下样例输入中给出的地形。

我们将高度为 3 的点称为山峰,因为没有比它们更高的点了。但是,尽管高度为 3 的山峰左侧的高度为 2 的点都高于或等于它们相邻的邻居(即上下左右相邻的点),我们并不想把它们称为山峰,因为我们可以从这些点出发,在不经过太低区域的情况下到达一个更高的点(即高度为 3 的山峰)。相比之下,我们确实想把右侧高度为 2 的区域称为山峰,因为如果我们想走到高度为 3 的山峰,我们必须先下降到高度为 0 的点。

在上述例子之后,我们引入 $d$-山峰($d$-summit)的概念。一个高度为 $h$ 的点是 $d$-山峰,当且仅当在不经过高度小于或等于 $h - d$ 的点的情况下,无法到达任何更高(高度大于 $h$)的点。换句话说,从该点出发到任何更高点的所有路径中,都必须包含至少一个高度小于或等于 $h - d$ 的点。

本题的任务是,给定一个由整数高度组成的矩形网格和一个整数 $d$,求出 $d$-山峰的数量。

输入格式

第一行包含一个正整数:测试用例的数量,最多为 100。随后是每个测试用例的数据:

  • 第一行包含三个整数 $1 \le h \le 500$,$1 \le w \le 500$ 和 $1 \le d \le 1\,000\,000\,000$。其中 $h$ 和 $w$ 是地图的维度,$d$ 的定义如前文所述。
  • 接下来 $h$ 行,每行包含 $w$ 个整数。其中第 $y$ 行的第 $x$ 个整数表示点 $(x, y)$ 的高度(高度在 $0$ 到 $1\,000\,000\,000$ 之间)。

输出格式

对于每个测试用例:

  • 输出一行,包含一个整数,表示 $d$-山峰的数量。

样例

输入 1

1
6 10 2
0 0 0 0 0 0 0 0 0 0
0 1 2 1 1 1 1 0 1 0
0 2 1 2 1 3 1 0 0 0
0 1 2 1 3 3 1 1 0 0
0 2 1 2 1 1 1 0 2 0
0 0 0 0 0 0 0 0 0 0

输出 1

4

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.