主题:[活动]回字迷宫
神鬼天王
[专家分:30] 发布于 2009-09-13 18:22:00
程序
回复列表 (共1个回复)
沙发
phile [专家分:2310] 发布于 2009-09-13 18:23:00
CLS
INPUT N
AA = TIMER
P = (1 + N) * N / 2
H = N * 2 - 1
DIM A(N, N), B(H TO P)
FOR I = 1 TO N
A = 1
FOR J = 1 TO N
PRINT A;
A(I, J) = A
IF I > J THEN A = A + 1
IF I + J > N THEN A = A - 1
NEXT J
PRINT
NEXT I
FOR I = H TO P
B(I) = 1
FOR J = 2 TO INT(SQR(I))
IF I MOD J = 0 THEN B(I) = 0: EXIT FOR
NEXT J, I
I = 1
J = 1
GOSUB 100
PRINT T * 2, INT(TIMER - AA)
END
100
S = S + A(I, J)
IF I = N AND J = N THEN T = T + B(S)
IF I = 2 AND J = 1 THEN RETURN
J = J + 1
IF J <= N THEN GOSUB 100
J = J - 1
I = I + 1
IF I <= N THEN GOSUB 100
I = I - 1
S = S - A(I, J)
RETURN
我来回复