主题:[讨论]有趣的幻方
世界型帅哥
[专家分:0] 发布于 2006-10-29 10:16:00
[em10]14把1-8这8个数放入下图8个格中,要求相邻的格(横,竖,对角线)上填的数不连续.
┌─┐
│①│
┌─┼─┼─┐
│②│③│④│
├─┼─┼─┤
│⑤│⑥│⑦│
└─┼─┼─┘
│⑧│
└─┘
回复列表 (共2个回复)
沙发
老大徒伤悲 [专家分:29120] 发布于 2006-10-30 13:55:00
穷举!
板凳
hxy_anhui [专家分:320] 发布于 2009-01-30 12:02:00
CLS
PRINT TIME$
FOR A = 1 TO 8
A(1) = A
FOR B = 1 TO 8
A(2) = B
FOR C = 1 TO 8
A(3) = C
FOR D = 1 TO 8
A(4) = D
FOR E = 1 TO 8
A(5) = E
FOR F = 1 TO 8
A(6) = F
FOR G = 1 TO 8
A(7) = G
FOR H = 1 TO 8
A(8) = H
IF A * B * C * D * E * F * G * H = 40320 AND A + B + C + D + E + F + G + H = 36 THEN
FOR I = 1 TO 17
READ Q
IF ABS(A(Q \ 10) - A(Q MOD 10)) = 1 THEN 10
NEXT I
FOR I = 1 TO 7
FOR J = I + 1 TO 8
IF A(I) = A(J) THEN GOTO 10
NEXT J
NEXT I
S = S + 1
FOR I = 1 TO 8
PRINT A(I);
NEXT I
PRINT
10 RESTORE
NEXT H
NEXT G
NEXT F
NEXT E
NEXT D
NEXT C
NEXT B
NEXT A
PRINT S
DATA 23,34,56,67,25,36,47,13,68
DATA 12,35,46,78,14,37,26,58
PRINT TIME$
END
我来回复