主题:蛇型矩阵
下一个永远
[专家分:0] 发布于 2005-03-19 11:48:00
矩阵按下图排列,这是个5*5矩阵,要求输入矩阵范围在3到10
15 16 22 23 25
7 14 17 21 24
6 8 13 18 20
2 5 9 12 19
1 3 4 10 11
各位,考虑一下哦...谢谢啦
回复列表 (共27个回复)
11 楼
我的电脑 [专家分:990] 发布于 2007-08-08 09:39:00
cls
input "h,l:",h,l
dim s(h,l)
xx=1:yy=-1
for i=1 to h*l
x=x+xx:y=y+yy
if x<1 or x>h or y<1 or y>l then swap xx,yy
if x>h then x=h:y=y+2
if y>l then y=l:=x+2
if x<1 then x=1
if y<1 then y=1
s(x,y)=i
next i
for i=1 to h
for j=1 to l
print using "###";s(i,j);
next j:print:next i
end
12 楼
小精灵1号 [专家分:1040] 发布于 2007-08-08 09:42:00
CLS
INPUT N
DIM A(N, N)
FOR I = 1 TO 4: READ X1(I), Y1(I), X2(I), Y2(I): NEXT I
DATA 1,0,1,-1,0,1,1,1,-1,0,-1,1,0,-1,0,0
X = 0: Y = 1
FOR I = N - 1 TO 0 STEP -2
IF I = 0 THEN A(X + 1, Y) = N * N: GOTO 10
FOR J = 1 TO 4
FOR K = 1 TO I
X = X + X1(J): Y = Y + Y1(J): S = S + 1: A(X, Y) = S
NEXT K
X = X + X2(J): Y = Y + Y2(J)
NEXT J
NEXT I
10 FOR I = 1 TO N
FOR J = 1 TO N
PRINT USING "###"; A(I, J);
NEXT J: PRINT
NEXT I
END
13 楼
我的电脑 [专家分:990] 发布于 2007-08-09 10:53:00
cls
input "h,l:",h,l
dim s(h,l)
xx=1:yy=-1
for i=1 to h*l
x=x+xx:y=y+yy
if x<1 or x>h or y<1 or y>l then swap xx,yy
if x>h then x=h:y=y+2
if y>l then y=l:x=x+2
if x<1 then x=1
if y<1 then y=1
s(x,y)=i
next i
for i=1 to h:for j=1 to l
print using "###";s(i,j);
next j:print:next i
end
14 楼
我的电脑 [专家分:990] 发布于 2007-08-09 11:07:00
input "h,l:",h,l
dim s(h,l)
xx=1
yy=-1
for i=1 to h*l
x=x+xx
y=y+yy
if x<1 or x>h or y<1 or y>l then swap xx,yy
if x>h then
x=h
y=y+2
endif
if y>l then
y=l
x=x+2
endif
if x<1 then x=1
if y<1 then y=1
s(x,y)=i
next
for i=1 to h
print
for j=1 to l
print using "###";s(i,j);
next j,i
15 楼
网虫一号 [专家分:1230] 发布于 2007-09-21 17:55:00
CLS
INPUT N
DIM A(N, N)
XX = 1: YY = -1
FOR I = 1 TO N * N
X = X + XX: Y = Y + YY
IF X < 1 OR X > N OR Y < 1 OR Y > N THEN SWAP XX, YY
IF X > N THEN X = N: Y = Y + 2
IF Y > N THEN Y = N: X = X + 2
IF X < 1 THEN X = 1
IF Y < 1 THEN Y = 1
A(X, Y) = I
NEXT I
FOR I = N TO 1 STEP -1
FOR J = 1 TO N
PRINT USING "###"; A(J, I);
NEXT J: PRINT
NEXT I
END
16 楼
我的电脑 [专家分:990] 发布于 2007-09-21 18:09:00
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
Y = I + 1 - X: K = K + 1
A(X, Y) = k
NEXT J, I
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
17 楼
QB小猪 [专家分:1200] 发布于 2007-09-24 14:08:00
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=n to 1 step -1:for j=1 to n '变换这里的终值和初值,可以达到8种不同效果
?using"###";a(i,j);
next j
?
next i
end
18 楼
Lovely哆啦 [专家分:1360] 发布于 2007-09-30 22:09:00
[quote]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=n to 1 step -1:for j=1 to n '变换这里的终值和初值,可以达到8种不同效果
?using"###";a(i,j);
next j
?
next i
end[/quote]
步长值也可以变化!
19 楼
Lovely哆啦 [专家分:1360] 发布于 2007-10-01 14:16:00
[quote]对于这个,我总是建议:直接打![/quote]
怎么可以直接打?
(那是懒惰的人的想法!)
20 楼
QB小猪 [专家分:1200] 发布于 2007-10-08 10:33:00
cls
input n:dim a(n,n)
for i=1 to n*2-1
if i mod 2=0 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
a(x,i+1-x)=i
next j,i
这是存数。
我来回复