首页 > 解决方案 > 时间复杂度和算法加速

问题描述

代码需要超过 1 秒时

约束 1≤T≤10^5 1≤P≤10^5 1≤H≤10^6

如何减少我的代码所花费的时间

# cook your dish here
def check(h, p):
    while p>0:
        if h<=0:
            return 1
        if h-p>=0:
            h = h-p
        else:
            h=0
        p = p/2
        # print(h,p)
    return 0
for _ in range(int(input())):
    h, p = map(int, input().split())
    print(check(h,p))

标签: pythonpython-3.xtimetime-complexityspace-complexity

解决方案


推荐阅读