A7758 | Map
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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?
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?
输入格式
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 $10^{9}$ .
输出格式
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.
输入输出样例
输入 #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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted