再来个递归二分法。应该不会内存溢出。#include <Array.au3>
Local $avArray[10000], $anArray[10000];一万个数
Local $n[4]
$begin = TimerInit()
For $i = 0 To UBound($avArray) - 1
$abc=Random(1, 100, 1)
$avArray[$i] = $abc
$anArray[$i] = $abc
Next
$half = UBound($avArray) / 2
$truehalf=$half
$n[0] = $half
$n[1] = UBound($avArray)
$num=Random(0, UBound($avArray) - 1, 1)
_ArrayDelete($avArray, $num) ;从数组中随机删除一个元素
;MsgBox(0,0,$num)
Runs()
For $i=Int($n[0]) To Int($n[1])
If $avArray[$i]<>$anArray[$i] Then
MsgBox(0,TimerDiff($begin),$i&@TAB&$avArray[$i]&@CRLF&$num&@TAB&"校验")
ExitLoop
EndIf
Next
Func Runs()
If $avArray[$half-1]=$anArray[$half-1] Then
If $n[1]-$n[0]<=4 Then
;MsgBox(0,TimerDiff($begin),"只能是"&$n[0]&"--"&$n[1])
Return
EndIf
add()
Else
jian()
EndIf
EndFunc
Func add()
$n[2]=$n[0]
$half=($n[1]-$n[0])/2+$n[0]
$n[0]=$half
Runs()
EndFunc
Func jian()
$n[0]=$n[2]
$n[2]=$n[0]
$n[3]=$n[1]
$half=($n[1]-$n[0])/2+$n[0]
$n[1]=$half
If $avArray[$half-1]=$anArray[$half-1] Then
$n[0]=$n[1]
$n[1]=$n[3]
;MsgBox(0,"","只能是")
;_ArrayDisplay($n,"减")
Runs()
Else
;_ArrayDisplay($n,"减")
Runs()
EndIf
EndFunc
|