主题:蛇型矩阵
下一个永远
[专家分: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个回复)
沙发
飞鸟12 [专家分:2830] 发布于 2005-03-19 12:29:00
只做了一半[em12][em12][em12]
1 3 4 10 11 21
2 5 9 12 20
6 8 13 19
7 14 18
15 17
16
DECLARE SUB printf ()
DIM SHARED num, x, dx, y, dy
CLS : INPUT "n=", n
CLS : n = 2 * (n - 1)
num = 0: x = 1: y = 1
dx = 0: dy = 0: printf
FOR i = 1 TO n STEP 2
dx = 0: dy = 1: printf
FOR j = 1 TO i
dx = 1: dy = -1: printf
NEXT j
dx = 1: dy = 0: printf
FOR j = 1 TO i + 1
dx = -1: dy = 1: printf
NEXT j
NEXT i
SUB printf
num = num + 1
x = x + dx: y = y + dy
LOCATE 2 * y, 4 * x: PRINT LTRIM$(STR$(num))
END SUB
板凳
战火神鹰 [专家分:0] 发布于 2005-03-19 16:35:00
djisfhckusdncasdghicuhskjc nauoidhrewyrqfgojdfcxnvjkcxhvioayriogquteroijhsldnvlchoiawurogiquwiogwfjglksmnvckljfsdhidvjehwurhguiohdsjgdJAXIOHSOIFHISADCLKSLSJVIJRIWGUAIWJGKLSCNVLKCSVKJLKSFJKLSJGKLFSJGSDGJUIOEWRUOIUOIJOJVLKMXCVLKC[em1]
3 楼
飞鸟12 [专家分:2830] 发布于 2005-03-20 11:45:00
[img]http://www.programfan.com/club/face/63.gif[/img]你什么意思啊?
4 楼
飞鸟12 [专家分:2830] 发布于 2005-03-29 22:14:00
终于解决了:
CLS
INPUT "n="; n
DIM a(n, n)
x = 1: y = 1: dx1 = 0: dy1 = 1: dx2 = 1: dy2 = -1
a(1, 1) = 1: a(n, n) = n ^ 2
FOR i = 2 TO n
a(x + dx1, y + dy1) = a(x, y) + 1
x = x + dx1: y = y + dy1
a(n + 1 - x, n + 1 - y) = n ^ 2 + 1 - a(x, y)
FOR j = 1 TO i - 1
a(x + dx2, y + dy2) = a(x, y) + 1
x = x + dx2: y = y + dy2
a(n + 1 - x, n + 1 - y) = n ^ 2 + 1 - a(x, y)
NEXT j
SWAP dx1, dy1: SWAP dx2, dy2
NEXT i
CLS
FOR i = 1 TO n
FOR j = 1 TO n
LOCATE n + 1 - i, 3 * j: PRINT a(j, i);
NEXT j
NEXT i
5 楼
litboat [专家分:140] 发布于 2005-04-08 12:42:00
这是我编的程序
INPUT b:CLS:FOR a=1TO (b+1)\2:FOR c=0TO b-2*a+1:d=4*(a-1)*(b+1-a)+c+1:e=4*a-3:f=b-a+1:g=b-2*a+1:LOCATE a+c,e:?d;:LOCATE f,e+4*c:?d+f-a;:LOCATE f-c,4*f-3:?d-1+2*b-e;:LOCATE a,e+4*(g-c):?d+3*g;:LOCATE a,e:?d-c;:NEXT:NEXT
n需要>=1 <=19
共218字节
我和同屋一同学比赛编这道题,我用quickbasic4.5,他用tc2.0,方法任意,看谁的程序最短
呵呵不好意思,为了追求短小,一点可读性都没有了
6 楼
litboat [专家分:140] 发布于 2005-04-08 12:51:00
我想,还是处理一下的好
CLS
INPUT "n=",n
CLS
FOR a=1 TO (b+1)\2
FOR c=0 TO b-2*a+1
LOCATE a+c,4*a-3
PRINT 4*(a-1)*(b+1-a)+c+1;
LOCATE b-a+1,4*a-3+4*c
PRINT 4*(a-1)*(b+1-a)+b-2*a+2+c;
LOCATE b-a+1-c,4*(b-a)+1
PRINT 4*(a-1)*(b+1-a)+2*b-4*a+3+c;
LOCATE a,4*a-3+4*(b-2*a+1)-4*c
PRINT 4*(a-1)*(b+1-a)+1+3*(b-2*a+1)+c;
LOCATE a,4*a-3
PRINT 4*(a-1)*(b+1-a)+1;
NEXT
NEXT
最后一个locate/print语句从计算方法上看,是完全多余的
但是经过几次试验之后发现删去之后,无法正确打印
肯定是我哪里想错了
谁能帮帮我啊
7 楼
litboat [专家分:140] 发布于 2005-04-08 12:58:00
奇怪...竟然看错题了
不好意思,嘿嘿
8 楼
def [专家分:3380] 发布于 2005-04-09 15:19:00
对于这个,我总是建议:直接打!
9 楼
jstzzyt [专家分:0] 发布于 2007-08-05 13:26:00
CLS
我做出来了:
INPUT N
DIM A(N, N)
I = N: J = 1
S = (1 + N) * N / 2
FOR K = 1 TO S
A(I, J) = K
A(N + 1 - I, N + 1 - J) = N * N + 1 - K
IF (I + J) MOD 2 = 0 THEN
IF J = 1 THEN I = I - 1 ELSE I = I - 1: J = J - 1
ELSE
IF I = N THEN J = J + 1 ELSE J = J + 1: I = I + 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
10 楼
网虫一号 [专家分:1230] 发布于 2007-08-08 09:36: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
我来回复