首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > PB >

完小两年级数学题.

2013-03-01 
小学两年级数学题...可能和PB和数据库没什么关系...不过这道题严重挑战了楼猪的智商!女朋友做家教碰到的:1

小学两年级数学题...
可能和PB和数据库没什么关系...
不过这道题严重挑战了楼猪的智商!完小两年级数学题.

女朋友做家教碰到的:
10个数从0到9,不能重复填写
要求往括号里填:
1:  ( )+( )=( )
2:  ( )+( )=( )
3:  ( )*( )=( )( )
满足以上三个式子

楼猪用了MATLAB,VC++写
表示能力有限
最后还是靠手算算出来的

这里有点说明:
这里能取巧,就是0+N=N所以0肯定在第三个式子里,大家愿意的话花点时间都能算出来;
就是关于这个的算法,怎么用PB去实现,求大神~
挽尊...



[解决办法]
1+7=8
3+6=9
4*5=20
[解决办法]
穷举法嘛。
long n[10]
n[1]=1
....
n[10]=0

int a,b,c,d,e,f,g,h,i,j
for a=1 to 10
  for b=1 to 10
    if a=b continue
    for c=1 to 10  
      if c=a or c=b continue
      if  n[a] + n[b] <> n[c] then continue
      for d=1 to 10
          if d=a or d=b or d=c then continue
          for e=1 to 10
             if e=a or e=b or e=c or e=d then continue
             for f=1 to 10
                 if .....
                 for g=1 to 10
                     ....

                             if n[g] * n[h] = n[i]*10+n[j] then
                                messagebox('结果',string(n[a]) + '+' +string(n[b])+'='+string(n[c])+'~r~n'+....)
                                return
                             end if
                      
                   end if 

    next
  next
next
[解决办法]

引用:
穷举法嘛。
long n[10]
n[1]=1
....
n[10]=0

int a,b,c,d,e,f,g,h,i,j
for a=1 to 10
  for b=1 to 10
    if a=b continue
    for c=1 to 10  
      if c=a or c=b continue


      if  n[a] + n[b] <> n[……



你还是用迭代吧。

热点排行
Bad Request.