2D MATRIX statement for 5 x 5 Grid

删除回忆录丶 提交于 2020-01-07 09:30:33

问题


Given a 5 x 5 Grid comprising of tiles numbered from 1 to 25 and a set of 5 start-end point pairs. For each pair,find a path from the start point to the end point. The paths should meet the below conditions:

a) Only Horizontal and Vertical moves allowed.

b) No two paths should overlap.

c) Paths should cover the entire grid

Input consist of 5 lines. Each line contains two space-separated integers,Starting and Ending point.

Output: Print 5 lines. Each line consisting of space-separated integers,the path for the corresponding start-end pair. Assume that such a path Always exists. In case of Multiple Solution,print any one of them.

Sample Input

1 22

4 17

5 18

9 13

20 23

Sample Output

1 6 11 16 21 22

4 3 2 7 12 17

5 10 15 14 19 18

9 8 13

20 25 24 23


回答1:


i think there should be restriction or it lacks some more information about the input ( start point and endpoint) because if we take following input then covering whole grid is not possible 1 22, 6 7, 11 12, 16 17, 8 9



来源:https://stackoverflow.com/questions/31098661/2d-matrix-statement-for-5-x-5-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!