Commit 327d0e70 by BellCodeEditor

auto save

parent 79fcccb9
Showing with 16 additions and 13 deletions
# 使用二分查找法,找出9和20在列表里面的索引 # 使用二分查找法,找出9和20在列表里面的索引
from random import * from random import *
b = randint(1,1000000) a = [94,91,90,88,87,83,81,80,79,77,76]
l = 1 #for i in range(1,10001):
h = 1000000 #a.append(i)
while l <= h: n = 88
def b (a,n):
l = 0
h = len(a)-1
while l <= h:
m = (l + h) // 2 m = (l + h) // 2
if m == b: c = a[m]
print(str(b) + '找到了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!,' + str(m)) if c == n:
break return m
elif m > b: elif c > n:
h = m-1
elif m < b:
l = m + 1 l = m + 1
else: elif c < n:
print('找不到!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') h = m-1
return None
print(b(a,88))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment