主题:[原创]迷宫程序,大家看看多顶顶
我爱qbasic
[专家分:160] 发布于 2009-07-13 18:49:00
迷宫程序,大家看看多顶顶,也提提意见,啊~~
最后更新于:2009-08-10 14:18:00
回复列表 (共15个回复)
11 楼
905482852 [专家分:380] 发布于 2009-09-04 20:50:00
[quote][quote][quote]没程序啊,哎……
我来发一个吧:
CLS
INPUT "X, y = ", x, y
DIM a(12, 12)
FOR i = 1 TO x
FOR j = 1 TO y
PRINT "A("; LTRIM$(RTRIM$(STR$(i))); ","; LTRIM$(RTRIM$(STR$(j))); ")=";
INPUT "", a(i, j)
IF a(i, j) = 1 THEN flag = 1
IF a(i, j) <> 1 AND a(i, j) <> 0 THEN PRINT "Data Error!": END
NEXT j, i
IF flag <> 1 THEN PRINT "Data Error!": END
CLS
FOR i = 1 TO x
FOR j = 1 TO y
PRINT USING "###"; a(i, j);
NEXT j: PRINT
NEXT i
PRINT "Press any key to continue(Press E to end)"
DO
z$ = INKEY$
LOOP UNTIL z$ <> ""
IF z$ = "E" THEN END
CLS : a$ = STRING$(3, CHR$(219)): b$ = STRING$(3, CHR$(176))
DIM s(100), x(100), y(100)
FOR i = 1 TO x
FOR j = 1 TO y
IF a(i, j) = 1 THEN LOCATE i, j * 3: PRINT a$
NEXT j, i
FOR i = 1 TO 4: FOR j = 1 TO 2
READ v(i, j)
NEXT j, i: DATA 0,1,1,0,0,-1,-1,0
LOCATE 12: PRINT "Press any key to run": d$ = INPUT$(1)
INPUT "Start I, J = ", x, y
y = y - 1
INPUT "End I, J = ", xe, ye
p = 0: x(p) = x: y(p) = y: i = 0
IF xe <= 0 OR ye <= 0 THEN PRINT "Data Error!": END
IF a(xe, ye) = 1 THEN PRINT "Data Error!": END
PRINT
DO
i = i + 1
IF i <= 4 THEN
x = x(p) + v(i, 1): y = y(p) + v(i, 2)
IF a(x, y) = 0 THEN
p = p + 1: s(p) = i: x(p) = x: y(p) = y
a(x, y) = 2
i = 0
GOSUB 10
END IF
ELSE
GOSUB 10
i = s(p): p = p - 1
END IF
LOOP UNTIL p = 0 OR x = xe AND y = ye
IF p = 0 THEN
PRINT "Not Find"
ELSE
LOCATE 14: PRINT "Start"; 2; ","; 0; "---->";
FOR i = 1 TO p
PRINT x(i); ","; y(i); "---->";
NEXT i
PRINT "Finish"
END IF
END
10 LOCATE x(p), y(p) * 3: FOR k = 1 TO 30000: NEXT
IF i <= 4 THEN PRINT USING "##"; p ELSE PRINT b$
RETURN
[/quote]
此题可以考虑用递归!![/quote]
递归的思路也是回溯!!!
[/quote]
12 楼
phile [专家分:2310] 发布于 2009-09-05 12:18:00
为何引用?
13 楼
zhangyurui2000427 [专家分:80] 发布于 2009-09-19 15:11:00
[quote][quote][quote]没程序啊,哎……
我来发一个吧:
CLS
INPUT "X, y = ", x, y
DIM a(12, 12)
FOR i = 1 TO x
FOR j = 1 TO y
PRINT "A("; LTRIM$(RTRIM$(STR$(i))); ","; LTRIM$(RTRIM$(STR$(j))); ")=";
INPUT "", a(i, j)
IF a(i, j) = 1 THEN flag = 1
IF a(i, j) <> 1 AND a(i, j) <> 0 THEN PRINT "Data Error!": END
NEXT j, i
IF flag <> 1 THEN PRINT "Data Error!": END
CLS
FOR i = 1 TO x
FOR j = 1 TO y
PRINT USING "###"; a(i, j);
NEXT j: PRINT
NEXT i
PRINT "Press any key to continue(Press E to end)"
DO
z$ = INKEY$
LOOP UNTIL z$ <> ""
IF z$ = "E" THEN END
CLS : a$ = STRING$(3, CHR$(219)): b$ = STRING$(3, CHR$(176))
DIM s(100), x(100), y(100)
FOR i = 1 TO x
FOR j = 1 TO y
IF a(i, j) = 1 THEN LOCATE i, j * 3: PRINT a$
NEXT j, i
FOR i = 1 TO 4: FOR j = 1 TO 2
READ v(i, j)
NEXT j, i: DATA 0,1,1,0,0,-1,-1,0
LOCATE 12: PRINT "Press any key to run": d$ = INPUT$(1)
INPUT "Start I, J = ", x, y
y = y - 1
INPUT "End I, J = ", xe, ye
p = 0: x(p) = x: y(p) = y: i = 0
IF xe <= 0 OR ye <= 0 THEN PRINT "Data Error!": END
IF a(xe, ye) = 1 THEN PRINT "Data Error!": END
PRINT
DO
i = i + 1
IF i <= 4 THEN
x = x(p) + v(i, 1): y = y(p) + v(i, 2)
IF a(x, y) = 0 THEN
p = p + 1: s(p) = i: x(p) = x: y(p) = y
a(x, y) = 2
i = 0
GOSUB 10
END IF
ELSE
GOSUB 10
i = s(p): p = p - 1
END IF
LOOP UNTIL p = 0 OR x = xe AND y = ye
IF p = 0 THEN
PRINT "Not Find"
ELSE
LOCATE 14: PRINT "Start"; 2; ","; 0; "---->";
FOR i = 1 TO p
PRINT x(i); ","; y(i); "---->";
NEXT i
PRINT "Finish"
END IF
END
10 LOCATE x(p), y(p) * 3: FOR k = 1 TO 30000: NEXT
IF i <= 4 THEN PRINT USING "##"; p ELSE PRINT b$
RETURN
[/quote]
此题可以考虑用递归!![/quote]
递归的思路也是回溯!!!
[/quote]
14 楼
phile [专家分:2310] 发布于 2009-09-21 18:52:00
???
15 楼
小小DAVID [专家分:300] 发布于 2009-12-06 19:15:00
地规避回溯举哀已被
我来回复