我想算四个数的运算结果,然后和一个小数比较,合适的话就输出。。
我用的是下面的方法
dim a as integer,b as integer,c as integer,d as integer
dim x as double
 for a=20 to 150
   for b=20 to 150 
     for c=20 to 150
       for d=20 to 150
       if (a*b)/(c*d)<=x then 
        text1.text=a
        text2.text=b
        text3.text=c
        text4.text=d
      end if
   next d
   next c
   next b
   next a 
但是当X很小的时候,运算太慢了,几乎死机了。。
各位大哥看看,小弟怎么才能求出a,b,c,d 啊!

解决方案 »

  1.   

    dim   a   as   integer,b   as   integer,c   as   integer,d   as   integer 
    dim   x   as   double 
      for   a=20   to   150 
          for   b=20   to   150   
              for   c=150 to 20 step -1  
                  for   d=150   to  20 step -1
                  if   (a*b)/(c*d) <=x   then   
                    text1.text=a 
                    text2.text=b 
                    text3.text=c 
                    text4.text=d 
                end   if 
          next   d 
          next   c 
          next   b 
          next   a
      

  2.   

    a 与 b, c 与 d 是完全对等的,不必从头到尾计算一遍。dim       a       as       integer,b       as       integer,c       as       integer,d       as       integer   
    dim       x       as       doubledim m as long, n as long, tmp as long
    for m = 20 ^2 to 150 ^ 2
       n = m \ x
       if n > 150 ^ 2 then exit for
       if n > 20 ^ 2 then
          debug.print "following (a * b) / (c * d) < " & x
          tmp = m ^ 0.5
          for a = tmp to 20 step -1
             b = m \ a
             if b > 150 exit for
             if b >= 20 then debug.print "a = " & a, "b = " & b
          next a
          debug.print ""
          tmp = n ^ 0.5
          for c = tmp to 20 step -1
             d = n \ c
             if d > 150 exit for
             if d >= 20 then debug.print "c = " & c, "d = " & d
          next a 
          debug.print ""
       end if
    next m      
      

  3.   

    循环次数的问题。
    如果x很小,你的c,d都从最大的数开始递减的话,就可以少算很多次我是这样理解的
      

  4.   

    就是有四个数:a,b,c,d
    要求 (a*b)/(c*d) <=x
    X为任意一个小数
    求出满足要求的所有a,b,c,d
    楼上大哥明白了吗
      

  5.   

    其中a,b,c,d的取值范围都是20到150
      

  6.   

    我解释一下我最后一段代码的思路:1 a * b 的乘积的定义域是 20 的平方至 150 的平方,做这个循环。也就是先取得积 m 。
    2 n = m \ x 就是 c * d 的积。如果满足 20 ^2 <= n <= 150 则,这组 m, n 就是符合条件的积。
    3 把 m 和 n 分解成 2 * b, c * d。由于 a 和 b, 以及 c 和 d 是可互换的,解出一组足矣。所以最大循环至 m 平方根和 n 的平方根。  
      

  7.   

    dim a as integer,b as integer,c as integer
    dim x as double
      for a=20 to 150   
          for b=20 to 15-a
            for c=20   to   150  
                for d=20 to 150-a -b
                    text1.text=a   
                    text2.text=b   
                    text3.text=c   
                    text4.text=150-a-b-c
            next c   
          next b   
        next a
      

  8.   

    但是看你得程序只能得到一组解呀。
    text1.text=a   
    text2.text=b   
    text3.text=c   
    text4.text=d 
    即使前面满足了,也会被下一组满足的数据给冲掉
      

  9.   

    可以用
    print a,b,c,d
    来输出啊,关键是如何采用一个更合理的算法来取代for  next 四重循环啊