主题:急疯了!!!!!!
这是一个典型的深度优先搜索问题,下面给出程序清单,请在①②中填上内容,使程序完整。试试看程序能否正确运行(正确结果有37条路线)
CLS : FOR i = 1 TO 4: READ v(i, 1), v(i, 2): NEXT
DATA 2,1,1,2,2,-1,1,-2,2
p = 1: x = 1: y = 1: x(p) = x: y(p) = y: i = 0: xe = 9: ye = 5
WHILE p > 0
i = i + 1
IF i <= 4 THEN
x = x(p) + v(i, 1): y = y(p) + v(i, 2)
IF ① THEN
p = p + 1: s(p) = I: x(p) = x: y(p) = y: i = 0
IF ② THEN GOSUB 10
END IF
ELSE
i = s(p): p = p - 1
END IF
WEND: END
10 n = n + 1: PRINT n; " "; : FOR j = 1 TO p - 1: PRINT USING "#"; x(j);
PRINT ","; : PRINT USING "#"; y(j); : PRINT " --> "; : NEXT
PRINT USING "#"; x(j); : PRINT ","; : PRINT USING "#"; y(j): RETURN
【112】半张棋盘如图①所示,马从棋盘的左下角起跳,目标是棋盘的右上角。并规定马只许往右跳,不许往左跳。图中所示为其中一种跳行路线,请你设计一个程序,由计算机寻找并打印出马的所有可能的跳行的路线。图②所示为马向右的四种跳法。
CLS : FOR i = 1 TO 4: READ v(i, 1), v(i, 2): NEXT
DATA 2,1,1,2,2,-1,1,-2,2
p = 1: x = 1: y = 1: x(p) = x: y(p) = y: i = 0: xe = 9: ye = 5
WHILE p > 0
i = i + 1
IF i <= 4 THEN
x = x(p) + v(i, 1): y = y(p) + v(i, 2)
IF ① THEN
p = p + 1: s(p) = I: x(p) = x: y(p) = y: i = 0
IF ② THEN GOSUB 10
END IF
ELSE
i = s(p): p = p - 1
END IF
WEND: END
10 n = n + 1: PRINT n; " "; : FOR j = 1 TO p - 1: PRINT USING "#"; x(j);
PRINT ","; : PRINT USING "#"; y(j); : PRINT " --> "; : NEXT
PRINT USING "#"; x(j); : PRINT ","; : PRINT USING "#"; y(j): RETURN
【112】半张棋盘如图①所示,马从棋盘的左下角起跳,目标是棋盘的右上角。并规定马只许往右跳,不许往左跳。图中所示为其中一种跳行路线,请你设计一个程序,由计算机寻找并打印出马的所有可能的跳行的路线。图②所示为马向右的四种跳法。