华为笔试第一题,暴力
import copy count = 1 n = list(raw_input().split()) a = [int(i) for i in n] b = list(copy.deepcopy(a[1:(len(n)//2)])) minStep=[] t =[] for x in b: idx = a.index(x) tem = [x] y = x + idx while True: if y < len(n): tem.append(a[y]) y = y + a[y] else: break t.append(tem) p,q =[],[] for i in range(len(t)): r =0 count = 1 for j in range(len(t[i])): if count == 1: idx = a.index(t[i][j]) r += idx count += 1 r += t[i][j] if r == len(n)-1: p.append(count) elif r > len(n): q.append(-1) break if len(p)>0: print(min(p)) else: print(-1)
#笔试题目##华为#