主题:如何求蛇形方正?50分来抢!!!!
小勇士来了
[专家分:220] 发布于 2010-03-17 18:52:00
如何求蛇形方正?50分来抢!!!!
谁先谁得!!!!!!!
[fly]如何求蛇形方正?50分来抢!!!!我QQ:1078350005
加我!!(备注:我是编程!)[/fly]
最后更新于:2010-03-17 18:53:00
回复列表 (共11个回复)
沙发
ㄣ銀翼の魔術 [专家分:30] 发布于 2010-03-17 19:32:00
蛇行方阵。在一个N*N(N<20)的方阵中,
填入1到N*N个数,并要求构成如下的图案。
1 3 4 10 1 3 4 10 11
2 5 9 11 2 5 9 12 19
6 8 12 15 6 8 13 18 20
7 13 14 16 7 14 17 21 24
15 16 22 23 25
N=4时
N=5时
CLS
INPUT N
DIM A(N, N)
FOR I = 1 TO N * 2 - 1
IF I <= N THEN
IF I MOD 2 = 0 THEN X = I + 1 ELSE X = 0
ELSE
IF I MOD 2 = 0 THEN X = X + 1
END IF
FOR J = 1 TO N - ABS(N - I)
IF I MOD 2 = 0 THEN X = X - 1 ELSE X = X + 1
K = K + 1: A(X, I + 1 - X) = K
NEXT J, I
FOR I = 1 TO N
FOR J = 1 TO N
PRINT USING "###"; A(I, J);
NEXT J: PRINT
NEXT I
END
板凳
shadowfp [专家分:30] 发布于 2010-04-01 20:46:00
倒蛇:
CLS
COLOR 10
INPUT N
DIM S(N, N)
II = 1
JJ = 1
DIM A(N, N): K = 0
FOR X = 1 TO N
IF X MOD 2 = 0 THEN
TH = N: TL = N + 1 - X
FOR I = 1 TO X
K = K + 1: A(TH, TL) = K: TH = TH - 1: TL = TL + 1
NEXT I
ELSE
TH = N + 1 - X: TL = N
FOR I = 1 TO X
K = K + 1: A(TH, TL) = K: TH = TH + 1: TL = TL - 1
NEXT I
END IF
NEXT X
FOR X = N - 1 TO 1 STEP -1
IF X MOD 2 = 0 THEN
TH = X: TL = 1
FOR I = 1 TO X
K = K + 1: A(TH, TL) = K: TH = TH - 1: TL = TL + 1
NEXT I
ELSE
TH = 1: TL = X
FOR I = 1 TO X
K = K + 1: A(TH, TL) = K: TH = TH + 1: TL = TL - 1
NEXT I
END IF
NEXT X
CLS
FOR I = 1 TO N
FOR J = 1 TO N
PRINT USING "####"; A(I, J);
NEXT J
PRINT
NEXT I
END
正蛇:CLS
COLOR 10
INPUT N
DIM S(N, N)
II = 1
JJ = 1
DIM A(N, N): K = 0
FOR X = 1 TO N
IF X MOD 2 = 1 THEN
TH = N: TL = N + 1 - X
FOR I = 1 TO X
K = K + 1: A(TH, TL) = K: TH = TH - 1: TL = TL + 1
NEXT I
ELSE
TH = N + 1 - X: TL = N
FOR I = 1 TO X
K = K + 1: A(TH, TL) = K: TH = TH + 1: TL = TL - 1
NEXT I
END IF
NEXT X
FOR X = N - 1 TO 1 STEP -1
IF X MOD 2 = 1 THEN
TH = X: TL = 1
FOR I = 1 TO X
K = K + 1: A(TH, TL) = K: TH = TH - 1: TL = TL + 1
NEXT I
ELSE
TH = 1: TL = X
FOR I = 1 TO X
K = K + 1: A(TH, TL) = K: TH = TH + 1: TL = TL - 1
NEXT I
END IF
NEXT X
CLS
FOR I = N TO 1 STEP -1
FOR J = N TO 1 STEP -1
PRINT USING "####"; A(I, J);
NEXT J
PRINT
NEXT I
END
3 楼
小勇士来了2 [专家分:850] 发布于 2010-07-14 13:33:00
正的或反的,
是的。
4 楼
小勇士来了2 [专家分:850] 发布于 2010-07-14 13:33:00
加油!!!
5 楼
“三人禾” [专家分:30] 发布于 2010-07-15 16:00:00
CLS
INPUT n ’n行,n列。请输入!
DIM a(n, n)
i = n ’起始行
j = 1 ’起始列
di = -1 ’发生变化的行
dj = -1 ’发生变化的列
FOR k = 1 TO n * n
a(i, j) = k
i = i + di
j = j + dj
IF j > n AND i > n THEN
i = i - 2
j = n
di = -1 * di
dj = dj * -1
ELSEIF i < 1 AND j < 1 THEN
j = j + 2
i = 1
di = -1 * di
dj = -1 * dj
ELSEIF j < 1 THEN
j = 1
di = di * -1
dj = dj * -1
ELSEIF j > n THEN
j = n
i = i - 2
di = di * -1
dj = dj * -1
ELSEIF i < 1 THEN
j = j + 2
i = 1
di = di * -1
dj = dj * -1
ELSEIF i > n THEN
i = n
di = di * -1
dj = dj * -1
END IF
NEXT k
FOR i = 1 TO n
FOR j = 1 TO n
PRINT USING "####"; a(i, j); '输出
NEXT j
PRINT
NEXT i
SLEEP
END
6 楼
FFKK [专家分:1610] 发布于 2010-09-13 20:47:00
随手编的
CLS
INPUT n
DIM a(n, n)
i = n
j = 1
di = -1
dj = -1
FOR k = 1 TO n * n
a(i, j) = k
i = i + di
j = j + dj
IF j > n AND i > n THEN
i = i - 2
j = n
di = -1 * di
dj = dj * -1
ELSEIF i < 1 AND j < 1 THEN
j = j + 2
i = 1
di = -1 * di
dj = -1 * dj
ELSEIF j < 1 THEN
j = 1
di = di * -1
dj = dj * -1
ELSEIF j > n THEN
j = n
i = i - 2
di = di * -1
dj = dj * -1
ELSEIF i < 1 THEN
j = j + 2
i = 1
di = di * -1
dj = dj * -1
ELSEIF i > n THEN
i = n
di = di * -1
dj = dj * -1
END IF
NEXT k
FOR i = 1 TO n
FOR j = 1 TO n
PRINT USING "####"; a(i, j);
NEXT j
PRINT
NEXT i
SLEEP
END
7 楼
王19991122 [专家分:70] 发布于 2010-12-04 20:15:00
楼主,你的题目so easy
8 楼
huangyb731 [专家分:630] 发布于 2010-12-05 11:45:00
呵
9 楼
huangyb731 [专家分:630] 发布于 2010-12-05 20:24:00
楼主,你的题目so easy!!
10 楼
verysmartboy [专家分:1260] 发布于 2010-12-18 09:54:00
楼上的,简单就做啊。
我来回复