当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2971:"Switchback"

Special Judge 特殊评判
题目描述

A construction firm, which you work for, has signed a contract to complete construction of attraction called “Switchback”. The building site is a rectangle which is split into NxM squares (1 ≤ N, M ≤ 50), N rows down, M columns across. The square in the north-west corner of the building site is (1, 1), while the square in the south-east corner is (N, M).

By the moment of signing the contract the following work has already been done at the attraction building site. First, a mast was built in each of the squares. The height of the mast in the square (i, j) is Hij (1 ≤ Hij ≤ 100, natural). Second,  construction of a launching complex was started at the top of the mast with coordinates (a, b), where 1 ≤ aN, 1 ≤ bM.

The idea of the attraction is the following. A small carriage with passengers moves from one square to another adjacent square, square by square. It starts moving from the square with the launching complex and moves until it stops. It moves on rails built on tops of masts according to the following rules:

  • at the launching complex the carriage is slightly pushed so to start moving in any direction downwards;
  • on arrival to the next square the carriage can continue its movement in the same direction or can turn 90° to the right or to the left;
  • the carriage’s speed increases by one for each unit of height reduction while moving downwards; the carriage can not move downwards if its current speed is zero;
  • the carriage’s speed decreases by two for each unit of height increment while moving upwards. If the carriage moves upwards than its initial speed has to be sufficient to reach the next square;
  • the carriage’s speed during a transition to an adjacent square decreases by one while moving horizontally;
  • safety rules forbid to change the carriage’s speed during transition to an adjacent square by more than 2 units;
  • the carriage has brakes which can be used only to stop the carriage on arrival to the final square. However, safety rules forbid using brakes if the carriage’s speed on arrival to this square is more than three units.

The number of squares visited by the carriage during its trip is called attraction length. If the carriage visits a square more than once than each of the visits counts. The first square of the path does not count.

The construction firm has to build rails on tops of the masts. As the only programmer in the firm, you need to write a program which can find the longest possible path according to the rules above. It is guaranteed that this path exists and its length is greater than zero.

输入解释

The first line of the input contains values N, M, a, b. The next N lines contain values Hi,j, M values per line. The numbers in the input file’s lines are separated by one or more spaces.

输出解释

The output contains several lines. The first line contains an attraction length k. Next k lines contain coordinates of squares and describe the longest path.

输入样例
5 5 1 1
10 8 6 3 4
9  7 6 5 8
4  5 5 2 1
2  3 5 7 8
1  4 3 3 2
输出样例
14
2 1
2 2
1 2
1 3
2 3
3 3
3 2
3 1
4 1
4 2
5 2
5 3
5 4
5 5

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-2971

最后修改于 2020-10-29T06:48:46+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
3000 65536