CF15D.Map
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:128MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is an area map that is a rectangular matrix n × m, each cell of the matrix contains the average height of a corresponding area part. Peter works for a company that has to build several cities within this area, each of the cities will occupy a rectangle a × b cells on the map. To start construction works in a particular place Peter needs to remove excess ground from the construction site where a new city will be built. To do so he chooses a cell of the minimum height within this site, and removes excess ground from other cells of the site down to this minimum level. Let's consider that to lower the ground level from _h_2 to _h_1 (_h_1 ≤ _h_2) they need to remove _h_2 - _h_1 ground units.
Let's call a site's position optimal, if the amount of the ground removed from this site is minimal compared to other possible positions. Peter constructs cities according to the following algorithm: from all the optimum site's positions he chooses the uppermost one. If this position is not unique, he chooses the leftmost one. Then he builds a city on this site. Peter repeats this process untill he can build at least one more city. For sure, he cannot carry out construction works on the occupied cells. Would you, please, help Peter place cities according to the algorithm?
存在一张面积地图,它是一个 n×m 的矩形矩阵,矩阵中每个单元格包含对应区域部分的平均海拔高度。彼得就职于一家公司,该公司需在该区域内建造若干座城市;每座城市将占据地图上一个 a×b 的矩形区域。为在某处启动施工,彼得需要清除拟建城市所在施工场地上的多余土方。为此,他首先在该施工场地内选出海拔最低的单元格,并将该场地内其余所有单元格的海拔均削降至该最低海拔。我们假定:将海拔从 h2 降至 h1(其中 h1≤h2)所需清除的土方量为 h2−h1 单位。
我们将所需清除土方量最少的施工场地位置称为最优位置(即在所有可能的位置中,该位置对应的土方清除量最小)。彼得按如下算法建造城市:在所有最优位置中,他优先选择最靠上方的一个;若存在多个同样靠上的最优位置,则从中选择最靠左的一个,并在此处建造一座城市。彼得不断重复此过程,直到无法再建造至少一座新城市为止。当然,他不能在已被占用的单元格上进行施工。请您帮助彼得按照上述算法放置城市。
输入格式
The first line contains four space-separated integers: map sizes n, m and city sizes a, b (1 ≤ a ≤ n ≤ 1000, 1 ≤ b ≤ m ≤ 1000). Then there follow n lines, each contains m non-negative space-separated numbers, describing the height matrix. Each number doesn't exceed 109.
第一行包含四个以空格分隔的整数:地图尺寸 n、m 和城市尺寸 a、b(满足 1 ≤ a ≤ n ≤ 1000,1 ≤ b ≤ m ≤ 1000)。随后是 n 行,每行包含 m 个非负的、以空格分隔的数字,用于描述高度矩阵。每个数字均不超过 109。
输出格式
In the first line output k — the amount of constructed cities. In each of the following k lines output 3 space-separated numbers — the row number and the column number of the upper-left corner of a subsequent construction site, and the amount of the ground to remove from it. Output the sites in the order of their building up.
第一行输出 k —— 构造的城市数量。接下来的 k 行中,每行输出三个以空格分隔的数字:后续施工场地左上角的行号、列号,以及需从该处移除的土方量。按施工顺序输出这些施工场地。
输入输出样例
输入#1
2 2 1 2 1 2 3 5
输出#1
2 1 1 1 2 1 2
输入#2
4 4 2 2 1 5 3 4 2 7 6 1 1 1 2 2 2 2 1 2
输出#2
3 3 1 2 3 3 3 1 2 9
输入解题思路,AI测评打分。不知道怎么写?