回 帖 发 新 帖 刷新版面

主题:菜鸟解超难题,看了别吓着!

cls
Print "1=a,2=b,3=c,4=d,5=e"
print
for d1=1 to 5
for d2=1 to 5
for d3=1 to 5
for d4=1 to 5
for d5=1 to 5
for d6=1 to 5
for d7=1 to 5
for d8=1 to 5
for d9=1 to 5
for d10=1 to 5
p1=0
p2=0
p3=0
p4=0:pa4=0
p5=0
p6=0:pb6=0:pc6=0:pd6=0:pe6=0
p7=0
p8=0:pp8=0
p9=0:pp9=0
if d1=1 then pa4=pa4+1
if d2=1 then pa4=pa4+1
if d3=1 then pa4=pa4+1
if d4=1 then pa4=pa4+1
if d5=1 then pa4=pa4+1
if d6=1 then pa4=pa4+1
if d7=1 then pa4=pa4+1
if d8=1 then pa4=pa4+1
if d9=1 then pa4=pa4+1
if d10=1 then pa4=pa4+1
if d1=2 then pb6=pb6+1
if d2=2 then pb6=pb6+1
if d3=2 then pb6=pb6+1
if d4=2 then pb6=pb6+1
if d5=2 then pb6=pb6+1
if d6=2 then pb6=pb6+1
if d7=2 then pb6=pb6+1
if d8=2 then pb6=pb6+1
if d9=2 then pb6=pb6+1
if d10=2 then pb6=pb6+1
if d1=3 then pc6=pc6+1
if d2=3 then pc6=pc6+1
if d3=3 then pc6=pc6+1
if d4=3 then pc6=pc6+1
if d5=3 then pc6=pc6+1
if d6=3 then pc6=pc6+1
if d7=3 then pc6=pc6+1
if d8=3 then pc6=pc6+1
if d9=3 then pc6=pc6+1
if d10=3 then pc6=pc6+1
if d1=4 then pd6=pd6+1
if d2=4 then pd6=pd6+1
if d3=4 then pd6=pd6+1
if d4=4 then pd6=pd6+1
if d5=4 then pd6=pd6+1
if d6=4 then pd6=pd6+1
if d7=4 then pd6=pd6+1
if d8=4 then pd6=pd6+1
if d9=4 then pd6=pd6+1
if d10=4 then pd6=pd6+1
if d1=5 then pe6=pe6+1
if d2=5 then pe6=pe6+1
if d3=5 then pe6=pe6+1
if d4=5 then pe6=pe6+1
if d5=5 then pe6=pe6+1
if d6=5 then pe6=pe6+1
if d7=5 then pe6=pe6+1
if d8=5 then pe6=pe6+1
if d9=5 then pe6=pe6+1
if d10=5 then pe6=pe6+1
if (d1=1)or(d1=5) then pp8=pp8+1
if (d2=1)or(d2=5) then pp8=pp8+1
if (d3=1)or(d3=5) then pp8=pp8+1
if (d4=1)or(d4=5) then pp8=pp8+1
if (d5=1)or(d5=5) then pp8=pp8+1
if (d6=1)or(d6=5) then pp8=pp8+1
if (d7=1)or(d7=5) then pp8=pp8+1
if (d8=1)or(d8=5) then pp8=pp8+1
if (d9=1)or(d9=5) then pp8=pp8+1
if (d10=1)or(d10=5) then pp8=pp8+1
if (d1<>1)and(d1<>5) then pp9=pp9+1
if (d2<>1)and(d2<>5) then pp9=pp9+1
if (d3<>1)and(d3<>5) then pp9=pp9+1
if (d4<>1)and(d4<>5) then pp9=pp9+1
if (d5<>1)and(d5<>5) then pp9=pp9+1
if (d6<>1)and(d6<>5) then pp9=pp9+1
if (d7<>1)and(d7<>5) then pp9=pp9+1
if (d8<>1)and(d8<>5) then pp9=pp9+1
if (d9<>1)and(d9<>5) then pp9=pp9+1
if (d10<>1)and(d10<>5) then pp9=pp9+1
  if (d1=1)and(d2=2) then p1=1
  if (d1=3)and(d4=2) then p1=1
  if (d1=4)and(d5=2) then p1=1
  if (d1=5)and(d6=2) then p1=1:if p1<>1 then goto EENDD
   if (d2=1)and(d2=d3) then p2=1
   if (d2=2)and(d3=d4) then p2=1
   if (d2=3)and(d4=d5) then p2=1
   if (d2=4)and(d5=d6) then p2=1
   if (d2=5)and(d6=d7) then p2=1:if p2<>1 then goto EENDD
    if (d3=1)and(d3=d1) then p3=1
    if (d3=2)and(d3=d2) then p3=1
    if (d3=3)and(d3=d4) then p3=1
    if (d3=4)and(d3=d7) then p3=1
    if (d3=5)and(d3=d6) then p3=1:if p3<>1 then goto EENDD
     if d4=pa4+1 then p4=1:if p4<>1 then goto EENDD
      if (d5=1)and(d5=d10) then p5=1
      if (d5=2)and(d5=d9) then p5=1
      if (d5=3)and(d5=d8) then p5=1
      if (d5=4)and(d5=d7) then p5=1
      if (d5=5)and(d5=d6) then p5=1:if p5<>1 then goto EENDD
       if (d6=1)and(pa4=pb6) then p6=1
       if (d6=2)and(pa4=pc6) then p6=1
       if (d6=3)and(pa4=pd6) then p6=1
       if (d6=4)and(pa4=pe6) then p6=1
       if (d6=5)and(pa4<>pb6)and(pa4<>pc6)and(pa4<>pd6)and(pa4<>pe6) then p6=1:if p6<>1 then goto EENDD
        if (d7=1)and(d8=5) then p7=1
        if (d7=2)and(d8=5) then p7=1
        if (d7=3)and((d8=1)or(d8=5)) then p7=1
        if (d7=4)and((d8=3)or(d8=5)) then p7=1
        if (d7=5)and(d8=5) then p7=1:if p7<>1 then goto EENDD
         if (d8=1)and(pp8=2) then p8=1
         if (d8=2)and(pp8=3) then p8=1
         if (d8=3)and(pp8=4) then p8=1
         if (d8=4)and(pp8=5) then p8=1
         if (d8=5)and(pp8=6) then p8=1:if p8<>1 then goto EENDD
          if (d9=1)and((pp9=2)or(pp9=3)or(pp9=5)or(pp9=7)) then p9=1
          if (d9=2)and((pp9=1)or(pp9=2)or(pp9=6)) then p9=1
          if (d9=3)and((pp9=1)or(pp9=4)or(pp9=9)) then p9=1
          if (d9=4)and((pp9=1)or(pp9=8)) then p9=1
          if (d9=5)and((pp9=5)or(pp9=10)) then p9=1:if p9<>1 then goto EENDD
if (p1=1)and(p2=1)and(p3=1)and(p4=1)and(p5=1)and(p6=1)and(p7=1)and(p8=1)and(p9=1) then
    if ((d1=d2)and(d2<>d3)and(d3<>d4)and(d4<>d5)and(d5<>d6)and(d6<>d7)and(d7<>d8)and(d8<>d9)and(d9<>d10))or_
       ((d1<>d2)and(d2=d3)and(d3<>d4)and(d4<>d5)and(d5<>d6)and(d6<>d7)and(d7<>d8)and(d8<>d9)and(d9<>d10))or_
       ((d1<>d2)and(d2<>d3)and(d3=d4)and(d4<>d5)and(d5<>d6)and(d6<>d7)and(d7<>d8)and(d8<>d9)and(d9<>d10))or_
       ((d1<>d2)and(d2<>d3)and(d3<>d4)and(d4=d5)and(d5<>d6)and(d6<>d7)and(d7<>d8)and(d8<>d9)and(d9<>d10))or_
       ((d1<>d2)and(d2<>d3)and(d3<>d4)and(d4<>d5)and(d5=d6)and(d6<>d7)and(d7<>d8)and(d8<>d9)and(d9<>d10))or_
       ((d1<>d2)and(d2<>d3)and(d3<>d4)and(d4<>d5)and(d5<>d6)and(d6=d7)and(d7<>d8)and(d8<>d9)and(d9<>d10))or_
       ((d1<>d2)and(d2<>d3)and(d3<>d4)and(d4<>d5)and(d5<>d6)and(d6<>d7)and(d7=d8)and(d8<>d9)and(d9<>d10))or_
       ((d1<>d2)and(d2<>d3)and(d3<>d4)and(d4<>d5)and(d5<>d6)and(d6<>d7)and(d7<>d8)and(d8=d9)and(d9<>d10))or_
       ((d1<>d2)and(d2<>d3)and(d3<>d4)and(d4<>d5)and(d5<>d6)and(d6<>d7)and(d7<>d8)and(d8<>d9)and(d9=d10)) then_
       print d1;d2;d3;d4;d5;d6;d7;d8;d9;d10
EENDD:end if
next
next
next
next
next
next
next
next
next
next

回复列表 (共15个回复)

11 楼

楼主(xq712000),请你把这个题目的原题说一下。
物理模型,就是指我们要解决的具体事情。例如,鸡兔同笼问题(鸡兔同笼,数头40各,数脚100,问几只鸡、几只兔),就是一个典型的物理模型。
数学模型,就是二元一次方程组x+y=40;2x+4y=100
算法选择,有从1只鸡到40只鸡采用循环验证,也可以从1只兔到40只兔进行验证, 也可以从1只兔到25只兔进行验证, 也可以解方程。

12 楼


[url=http://www.programfan.com/club/showbbs.asp?id=179823&page=last#last]这是原题的链接[/url]

13 楼

傅斑竹及楼主,谢谢,我看了。
这样的问题用来锻炼逻辑推理是个不错作业。

不过对此,我没有研究的时间。

14 楼

晕!不要以为CPU的运算速度很快就把所有的事都丢给它!
   要是他什么都做了!还要程序员做什么?
   作为一个程序员你应该知道!你是利用CPU工作!CPU是为顾客
工作!你要劲可能的把程序简化!自己能做的事就做!不要老丢给
CPU!这只是一个小的程序,就这样!
要是做一个大的!那顾客还会用你写的“垃圾”程序吗?
   。。。。

15 楼

5楼的程序没问题,运行时间长也是没办法,它总共要出大约300MB的文本信息,怎么说也得显示一段时间吧

如果输出到文件,可以缩短很多时间,两分钟多就行:

open "xxxx.txt" for output as #1
for d1=1 to 5
for d2=1 to 5
for d3=1 to 5
for d4=1 to 5
for d5=1 to 5
for d6=1 to 5
for d7=1 to 5
for d8=1 to 5
for d9=1 to 5
for d10=1 to 5
 print #1, d1;d2;d3;d4;d5;d6;d7;d8;d9;d10
next
next
next
next
next
next
next
next
next
next
close #1
end

你如果想要知道纯粹的循环时间,可以注释掉中间的print语句。

我来回复

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