Office中国论坛/Access中国论坛
标题: 编程题目 [打印本页]
作者: Trynew 时间: 2005-9-20 18:42
标题: 编程题目
题目为:将1-9这9个数字分成三个3位数,要求分出的第一个3位数,正好是第二个三位数的
二分之一,是第三个3位数的三分之一。
作者: ui 时间: 2005-9-21 04:49
trynew之作,相必精彩,学习学习
作者: 海狸先生 时间: 2005-9-21 18:34
佩服佩服
[此贴子已经被作者于2005-9-21 14:18:16编辑过]
作者: LucasLynn 时间: 2005-9-22 16:25
看看
作者: LucasLynn 时间: 2005-9-22 16:32
不错,排除输出时候后,纯运算时间3.9毫秒:
Public Sub Ck()
Dim i As Integer, j As Integer, k As Integer
Dim t1 As Double, t2 As Double, w As String
t1 = Timer
For k = 1 To 100
For i = 123 To 333
For j = 1 To 9
If InStr(1, i & 2 * i & 3 * i, j) = 0 Then Exit For
Next j
If j > 9 Then w = i & " " & 2 * i & " " & 3 * i
Next i
Next k
t2 = Timer
Debug.Print (t2 - t1) / 100
End Sub
[此贴子已经被作者于2005-9-22 9:29:46编辑过]
作者: LucasLynn 时间: 2005-9-22 17:25
字符串操作是性能杀手,代码中尽量避免了使用字符串操作。
运行时间:0.98毫秒
Public Sub Test()
Dim i As Integer, j As Integer, k As Integer, l As Integer, m As Integer, num As Long
Dim t1 As Double, t2 As Double
Dim data() As Byte
Dim tags(8) As Boolean
Dim w As String
t1 = Timer
For m = 1 To 1000
For i = 1 To 3
For j = 1 To 9
If j <> i Then
For k = 1 To 9
If k <> i And k <> j Then
num = i * 100 + j * 10 + k
If num > 329 Then GoTo NOT_THIS
data = CStr(num * 1000000 + num * 2000 + num * 3)
Erase tags
For l = 0 To UBound(data) Step 2
If data(l) = 48 Then GoTo NOT_THIS
If tags(data(l) - 49) Then GoTo NOT_THIS
tags(data(l) - 49) = True
Next l
w = num & " " & num * 2 & " " & num * 3
End If
NOT_THIS:
Next k
End If
Next j
Next i
Next m
t2 = Timer
Debug.Print (t2 - t1) ; "毫秒"
End Sub
[此贴子已经被作者于2005-9-22 9:53:06编辑过]
作者: test2000 时间: 2005-9-22 18:44
领教了各位高手!!
作者: Trynew 时间: 2005-9-22 23:50
运行时间:0.298毫秒Public Sub Test4()
Dim i As Integer, j As Integer, k As Integer, l As Integer, m As Integer, Num As Long
Dim t1 As Double, t2 As Double
Dim data() As Byte
Dim tags(9) As Boolean
Dim w As String t1 = Timer
For m = 1 To 1000
For i = 1 To 3
For j = 1 To 9
If j <> i Then
For k = 1 To 9
If k <> i And k <> j Then
Num = i * 100 + j * 10 + k
If Num > 329 Then Exit For
'num = (num * 1000000 + num * 2000 + num * 3) Erase tags
'For l = 0 To UBound(data) Step 2
' If data(l) = 48 Then GoTo NOT_THIS
' If tags(data(l) - 49) Then GoTo NOT_THIS
' tags(data(l) - 49) = True
'Next l
tags(Num \ 100) = True
tags((Num Mod 100) \ 10) = True
tags(Num Mod 10) = True
tags((Num * 2) \ 100) = True
tags(((Num * 2) Mod 100) \ 10) = True
tags((Num * 2) Mod 10) = True
tags((Num * 3) \ 100) = True
tags(((Num * 3) Mod 100) \ 10) = True
tags((Num * 3) Mod 10) = True
If tags(1) And tags(2) And tags(3) And tags(4) And tags(5) And tags(6) And tags(7) And tags(8) And tags(9) Then
w = Num & " " & Num * 2 & " " & Num * 3
'Debug.Print w
End If
End If
'NOT_THIS:
Next k
End If
Next j
Next i
Next m
t2 = Timer
Debug.Print (t2 - t1); "毫秒"
End Sub
作者: LucasLynn 时间: 2005-9-23 19:57
这个强的,甘拜下风了!
对了,Trynew最近怎么不上QQ,我找了你好几次没找到。上次你对EDF提出的建议我都已经作了改进,现在已经完全支持事件参数了,找不到你,我先发论坛了。
[此贴子已经被作者于2005-9-23 14:36:12编辑过]
作者: LucasLynn 时间: 2005-9-24 22:03
手痒了,再来一段:0.219毫秒
Public Sub Test5()
Dim i As Integer, j As Integer, k As Integer, l As Integer, m As Integer
Dim Num As Integer, Num2 As Integer, Num3 As Integer
Dim t1 As Double, t2 As Double
Dim data() As Byte
Dim tag As Long
Dim tags(9) As Long
Dim w As String
t1 = Timer
For i = 0 To 9
tags(i) = 2 ^ i
Next i
For m = 1 To 10000
For i = 1 To 3
For j = 1 To 9
If j <> i Then
For k = 1 To 9
If k <> i And k <> j Then
Num = i * 100 + j * 10 + k
If Num > 329 Then Exit For
Num2 = Num + Num
Num3 = Num + Num2
tag = 0
tag = tag Or tags(i)
tag = tag Or tags(j)
tag = tag Or tags(k)
tag = tag Or tags((Num2) \ 100)
tag = tag Or tags(((Num2) Mod 100) \ 10)
tag = tag Or tags((Num2) Mod 10)
tag = tag Or tags((Num3) \ 100)
tag = tag Or tags(((Num3) Mod 100) \ 10)
tag = tag Or tags((Num3) Mod 10)
If tag = &H3FE Then
w = Num & " " & Num * 2 & " " & Num * 3
'Debug.Print w
End If
End If
Next k
End If
Next j
Next i
Next m
t2 = Timer
Debug.Print (t2 - t1) / 10; "毫秒"
End Sub
[此贴子已经被作者于2005-9-24 14:26:09编辑过]
作者: qxqjdy 时间: 2005-9-25 06:34
呵呵 ̄看看“电”脑们的杰作
作者: george 时间: 2005-10-22 01:19
思路
作者: nxjswt 时间: 2005-10-23 05:16
学习!算法的精彩长眼;
作者: damagekit 时间: 2005-10-23 05:31
佩服佩服
作者: TsuBasa 时间: 2005-10-29 10:27
佩服 佩服 看来现在ACCESS还是那么的上手啊
作者: Dghost 时间: 2006-1-23 03:01
长见识了,五体投地!!!
作者: glw 时间: 2006-2-2 17:43
看看
作者: 138688 时间: 2006-2-13 21:12
夺
作者: oyljl 时间: 2006-3-11 06:28
顶一下
作者: oyljl 时间: 2006-3-11 06:28
[em01][em02]
作者: zxzx2733 时间: 2006-5-29 09:57
1
作者: wuaza 时间: 2006-5-29 18:26
精彩之作
作者: qlm 时间: 2006-6-10 19:54
学下先!
作者: t小宝 时间: 2006-7-24 23:17
标题: 看下
看下高手过招
作者: 阿智 时间: 2006-7-27 21:24
不错
作者: xc1xa 时间: 2006-10-12 19:43
学习了。
作者: huangqinyong 时间: 2006-11-24 20:43
I see.........
作者: baije 时间: 2006-11-24 22:34
经典!!!
值得学习
作者: 若风1 时间: 2006-12-3 19:24
看看
作者: bjjgq 时间: 2007-3-29 06:27
佩服,高手的对决,精彩
作者: 方漠 时间: 2007-7-7 00:45
我也来一个,呵呵.
Sub TestAaron()
Dim D1, D2 As Double
Dim t1, t2, t3 As Integer
D1 = Timer
For t1 = 123 To 333
t2 = t1 * 2
t3 = t1 * 3
Call AddNo(t1, t2, t3)
Next
D2 = Timer
Debug.Print (D2 - D1); "毫秒"
End Sub
Sub AddNo(ByVal t1 As Integer, ByVal t2 As Integer, ByVal t3 As Integer)
Dim I As New Collection
On Error GoTo Abc
I.Add Left(t1, 1), Left(t1, 1)
I.Add Right(t1, 1), Right(t1, 1)
I.Add Left(Right(t1, 2), 1), Left(Right(t1, 2), 1)
I.Add Left(t2, 1), Left(t2, 1)
I.Add Right(t2, 1), Right(t2, 1)
I.Add Left(Right(t2, 2), 1), Left(Right(t2, 2), 1)
I.Add Left(t3, 1), Left(t3, 1)
I.Add Right(t3, 1), Right(t3, 1)
I.Add Left(Right(t3, 2), 1), Left(Right(t3, 2), 1)
If I.Count = 9 Then Debug.Print "T1: " & t1 & " T2: " & t2 & " T3: " & t3
Abc:
Exit Sub
End Sub
作者: 逛两脚 时间: 2009-3-27 17:31
标题: 做3个俯卧撑,,,走人
做3个俯卧撑,,,走人。。。楼下继续。。。
古之立大事者,不惟有超世之才,亦必有坚忍不拔之志。---魔兽剑圣异界纵横
极品家丁 龙蛇演义 恶魔法则 斗罗大陆 异界枪神 凡人修仙传 魔兽领主 超级农民 极品公子 飞升之后
作者: lurong 时间: 2009-6-16 13:07
学习学习
作者: ICEMAN 时间: 2010-4-1 17:28
数学黑洞
作者: yhliang1986 时间: 2010-6-20 16:07
热哈哈哈哈哈哈好
作者: GOODWIN 时间: 2021-8-24 19:31
学习学习
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) |
Powered by Discuz! X3.3 |