Created
August 26, 2021 16:44
-
-
Save asukaminato0721/b7c5a06016e21b8d10b2f0e963507a8e to your computer and use it in GitHub Desktop.
英特尔 2016 软件类研发在线测评 13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bfs(t: int): | |
vis = set() | |
q = [1] | |
level = 0 | |
while q: | |
for _ in range(len(q)): | |
t = q.pop(0) | |
if t == 2013: | |
return level | |
for j in [t + 1, t * 2]: | |
if j not in vis: | |
vis.add(j) | |
q.append(j) | |
level += 1 | |
print(bfs(1)) # 18 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment