数学规律 | HJ22 汽水瓶
# 最优解 while True: n=int(input()) if n==0:break print(n//2) # 我的代码 while True: try: b = int(input()) assert b != 0 cnt = 0 while b > 1: # 1个瓶子时,即使向老板借也不够还 cnt += b // 3 b = b%3 + b//3 if b % 3 != 0: # 向老板借空瓶子 while b > 1: for x in range(1, b): if (b + x)//3 + (b + x)%3 >= x: cnt += (b + x)//3 b = (b + x)//3 + (b + x)%3 - x break print(cnt) except: break
用时:30min
华为笔试刷题 文章被收录于专栏
高质量题: 1~40:HJ16,HJ22,HJ24,HJ26,HJ27,HJ28,HJ35,HJ37,HJ39; 40~80:HJ41,HJ42,HJ43,HJ44,HJ48,HJ50,HJ52,HJ53,HJ57,HJ61,HJ63,HJ64,HJ70,HJ71,HJ74,HJ77; 80~108:HJ82,HJ85,HJ88,HJ89,HJ93,HJ95,HJ98,HJ103,HJ107