【求证】3.19京东算法笔试_分鸡蛋题解
我是交了卷一瞬间才发现的BUG(没考虑y在各种3n后的情况),硬是调了半个多小时还没调出来,下面代码已经通过了我给的大部分自测用例了,不知道能否全AC,仅供参考and求证
真的哇的一声就哭了😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂😂🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣但凡快3分钟找到或者有点经验~
T = int(input()) while T > 0: T -= 1 x, y = [int(s) for s in input().split()] #print(x,y) count = 0 temp = 0 if x < y: count = y - x x = y while x != y: near = 3 * (int(x / 3) + 1) #找最近的 #print(near) std = list(range(x,temp)) #交卷前这里是list(range(x,near))就一直卡循环疯狂超时 print(std) if y in std: count += y-x x = y elif x % 3 == 0: temp = x x = int(x / 3) count += 1 else: count += near - x x = near print(x) print(int(count))
logo