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

建议使用的浏览器:

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

3426:Doors and... more doors

Special Judge 特殊评判
题目描述

When wondering through the labyrinth, the goal is usually to find some kind of door. Well, not this time.

A labyrinth consists of N × N cells, each 1 × 1 meter in size. Cells are separated by doors. Each door opens in a specific direction (as shown on the picture):

1. left outwards;
2. left inwards;
3. right outwards;
4. right inwards.

So a cell can be represented by two numbers describing doors on its eastern and southern sides according to the list above. The doors are just slightly less then 1 meter in width. The traveler in the labyrinth is also slightly less then 1 meter in diameter, so he has following limitations:

* He can not pull doors, only push them.
* After opening the door and entering the cell it leads to, he can not take a turn in the direction where the door opened, because the passage is blocked by the door. Doors have springs and close automatically when traveler leaves the cell.

Your program must find the shortest path for the traveler from north-western cell (1, 1) to south-eastern cell (N, N).

输入解释

Input file contains labyrinth size N followed by 2 × N2 numbers describing doors for each cell row by row. As there are no doors leading outside of labyrinth, values for eastern doors in the last column and southern doors in the last row are zero.

Constraints

1 ≤ N ≤ 1000

输出解释

Output file must contain the shortest path as a list of cell coordinates (column number, then row number), including both (1, 1) and (N, N) cells. If there are several solutions with the same length, output any one of them. If it is impossible to get to a destination cell, output a singe zero.

输入样例
Sample Input 1
2
2 3 0 4
1 0 0 0
Sample Input 2
3
4 3  1 4  0 1
3 3  2 3  0 4
2 0  1 0  0 0
输出样例
Sample Output 1
1 1
1 2
2 2
Sample Output 2
1 1
1 2
2 2
2 1
3 1
3 2
2 2
2 3
3 3
提示
Bold texts appearing in the sample sections are informative and do not form part of the actual data.

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

源链接: POJ-3426

最后修改于 2020-10-29T07:01:20+00:00 由爬虫自动更新

共提交 0

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