算法超时
lang_wolf
这个作者很懒,什么都没留下…
展开
-
PTA 1066 图像过滤——Python
今天在做PTA上的1066 图像过滤这道题时发现,使用*来对列表拆包输出时会超时,而改用join()函数时不会超时。 使用*拆包代码(会超时) M,N,A,B,rep = map(int,input().split()) res = [] for i in range(M): temp = ['{:0>3d}'.format(rep) if A <= j <= B els...原创 2020-05-04 12:06:43 · 249 阅读 · 0 评论 -
PTA 1073 多选题常见计分法——Python
最后一个测试点总是运行超时(未解决),先暂时记录一下。 #本题输入中有一下格式字符串: #(2 a c) (3 b d e) (2 a c) (3 a b e) #可以将其头和末尾的半个括号去掉: #2 a c) (3 b d e) (2 a c) (3 a b e #如此,它们之间是按') ('分割的 N,M = map(int,input().split()) answer = [] pro...原创 2020-05-03 16:28:00 · 472 阅读 · 0 评论 -
代码超时,有重复代码,写个函数代替
今天在做PTA上1093 字符串A+B这道题时,自己写的代码总有两个测试点超时。后来网上一查发现,即使用的方法相似还是超时。不是很明白时间差哪里了,只能先记下,以此为戒,以后有代码重复使用时,就写个函数,通过函数来调用。 修改前代码 import time start = time.time() A = input() B = input() temp = set(A + B) temp_dic...原创 2020-05-01 16:30:56 · 247 阅读 · 0 评论