回 帖 发 新 帖 刷新版面

主题:这题怎么解?

将A、B、C、D、E、F这六个变量排成如图1的三角形,这六个变量分别取1至6的整数,且均不相相同,求使三角形三条边上的变量之和相等的全部解,如图2就是一个解。
   A                2
  B C              3 5
 D E F            6 1 4
  图1              图2

回复列表 (共3个回复)

沙发

cls
for a=1 to 6
for b=1 to 6
for c=1 to 6
for d=1 to 6
for e=1 to 6 
for f=1 to 6
if a+b+c+d+e+f<>21 or a*b*c*d*e*f<>720 then 1
if a+b+d=a+c+b and d+e+f=a+b+d and a+c+f=d+e+f then 2
2 print tab(10);a
goto 3
3 print tab(9);b;c
goto 4
4 print tab(8);d;e;f;
l=l+1
1 next f,e,d,c,b,a
print "l="l;
end

一定要给分呀

板凳

其实做的很不错
不会是抄书的吧?
怎么有那么多多余的GOTO的?

3 楼

cls
for a=1 to 6
 for b=1 to 6
  for c=1 to 6
   for d=1 to 6
    for e=1 to 6
     for f=1 to 6
if a+b+d=a+c+f and a+b+d=d+e+f and a+c+f=d+e+f then
print tab(5);A
PRINT
PRINT TAB(3);d;" ";c
print
print tab(1);d;" ";e;" ";f
s=s+1
end if 
next f,e,d,c,b,a
print s
end






我来回复

您尚未登录,请登录后再回复。点此登录或注册