编程介的小学生 2017-04-22 07:57 采纳率: 20.5%
浏览 939
已采纳

Repair the Roof

Poor Windprayer. This time a terrible hurricane has seriously damaged the roof of his house. Now he wants to repair it with minimum cost.

You can consider the roof as a N by M rectangle, each grid is associated with a damage value, indicating the degree of damage of that grid (a grid is all right and shouldn't to be repaired if the damage value is 0).

Only 1*2 and 2*1 woods are available to repair the roof, and for some visual reason Windprayer will buy woods of same spec and same price. A piece of wood can be used to repair the roof if the price of it is not less than the sum of damage value of the two grids it covers.

Input:

The input file contain several test cases, each test case begin with two integers N and M (2 <= N, M <= 50), which is size of the roof. N lines follow, each with M non-negative integer not greater than 10000000, showing the damage value.
Output:

For each test case, if it's impossible to repair the roof, output "pat", otherwise, output the minimum cost in the first line, then in each of the following lines, output "(X1,Y1) (X2,Y2)", where (X1, Y1) and (X2, Y2) are positions that piece of wood will cover.

Sample input:

2 2
1 2
3 4

2 2
0 1
1 1
Sample output:

12
(0,1) (1,1)
(1,0) (0,0)
pat

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-05-06 15:48
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类