python - 时间复杂度和算法加速
问题描述
代码需要超过 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))
解决方案
推荐阅读
- javascript - 有没有办法使用javascript更改多个html文件的css?
- mysql - 选择 FOR UPDATE 给出重复键错误
- javascript - 单元测试:输入/输出
- php - 有没有办法在 Wordpress 导入/导出中包含 acf 图像
- officer - 漏洞?在定义 id 时,它会在不应该的时候说越界
- java - firebase 实时数据库验证规则
- c++ - 计数器不计算所有不同的元音
- java - 有没有办法优化这种方法?
- machine-learning - Pyspark 中的过采样或 SMOTE
- c# - 如何使用 EntityFramework 6.2 将 DbFunctions/SqlFunctions 调用提取到可重用的扩展/方法中?