编程介的小学生 2019-09-22 21:43 采纳率: 20.5%
浏览 76

Summits 程序实现的技术

Problem Description
You recently started working for the largest map drawing company in the Netherlands. Part of your job is to determine what the summits in a particular landscape are. Unfortunately, it is not so easy to determine which points are summits and which are not, because we do not want to call a small hump a summit. For example look at the landscape given by the sample input.

We call the points of height 3 summits, since there are no higher points. But although the points of height 2, which are to the left of the summit of height 3, are all higher than or equal to their immediate neighbours, we do not want to call them summits, because we can reach a higher point from them without going to low (the summits of height 3). In contrast, we do want to call the area of height 2 on the right a summit, since if we would want to walk to the summit of height 3, we first have to descend to a point with height 0.

After the above example, we introduce the concept of a d-summit. A point, with height h, is a d-summit if and only if it is impossible to reach a higher point without going through an area with height smaller than or equal to h-d.

The problem is, given a rectangular grid of integer heights and an integer d, to find the number of d-summits.

Input

Input
On the first line one positive number: the number of testcases, at most 100. After that per testcase:

One line with three integers 1 ≤ h ≤ 500, 1 ≤ w ≤ 500 and 1 ≤ d ≤ 1 000 000 000. h and w are the dimensions of the map. d is as defined in the text.

h lines with w integers, where the xth integer on the yth line denotes the height 0 ≤ h ≤ 1 000 000 000 of the point (x, y).

Output
Per testcase:

One line with the number of summits.

Sample Input
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

Sample Output
4

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿