我想算四个数的运算结果,然后和一个小数比较,合适的话就输出。。
我用的是下面的方法
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 啊!
我用的是下面的方法
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 啊!
解决方案 »
- microsoft internet controls 控件,b() = InetUpdate.OpenURL(lblremote.Caption, 1) 为什么返回总是空。
- 请问vb 中能实现类似Office 风格的工具栏吗?
- 问如何在vb中实现类似qq组一点击就上去或者下来的那种效果
- 如何使用treeview控件加载某一上目录下的所有文件(包括子文件夹里的文件)?
- 怎么判断一组check中那些已经被选择了呢
- 用MediaPlayer播放歌曲时,怎样得到运行的值,以及播放完时的结束值?在线等待!
- 使用INSTALLSHIELD 做安装时SUPPORTDIR目录里面的文件什么时候创建??
- 关于程序提速的问题
- 如何删除列表框的重复项目?
- 为何用Winsock,UDP协议,还要对方在线
- 如何隐藏同目录下所有文件
- vb vsflexgrid 用空行填充数据行下面的灰色背景
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
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
如果x很小,你的c,d都从最大的数开始递减的话,就可以少算很多次我是这样理解的
要求 (a*b)/(c*d) <=x
X为任意一个小数
求出满足要求的所有a,b,c,d
楼上大哥明白了吗
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 的平方根。
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
text1.text=a
text2.text=b
text3.text=c
text4.text=d
即使前面满足了,也会被下一组满足的数据给冲掉
print a,b,c,d
来输出啊,关键是如何采用一个更合理的算法来取代for next 四重循环啊