一个简单法

P2249 【深基13.例1】查找

fang111125687 @ 2024-06-16 16:43:26

m, n = map(int, input().split()) li = list(map(int, input().split())) cha = list(map(int, input().split())) for n in cha: a = -1 left = 0 right = m-1 while left <= right: mid = (right+left)//2 if li[mid] == n: a = mid+1 right = mid-1 elif li[mid] > n: right = mid-1 else: left = mid + 1 print(a)


by Anoif @ 2024-06-16 17:20:04

希望更丰富的展现?使用 Markdown


by zhchz @ 2024-08-01 23:46:50

马蜂良好


|