Commit 327d0e70 by BellCodeEditor

auto save

parent 79fcccb9
Showing with 18 additions and 15 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
m = (l + h) // 2 def b (a,n):
if m == b: l = 0
print(str(b) + '找到了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!,' + str(m)) h = len(a)-1
break while l <= h:
elif m > b: m = (l + h) // 2
h = m-1 c = a[m]
elif m < b: if c == n:
l = m + 1 return m
else: elif c > n:
print('找不到!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') l = m + 1
elif c < n:
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