第一道 过60%
开始还要低,时间太长问题:
发现后面循环太多有个情况是 一直转换没删除,这时跳出来,再判断就行
然后60%后,还有什么问题想不出来了
n,k = map(int,input().split())
S = list(input())
def del0(s):
n = []
i = 0
if '1' in s:
while s:
if s[0]!='0':
break
else:
s.pop(0)
else:
return 1
return 0
def turn(s):
for i in range(len(s)):
if s[i]=='0':
s[i] = '1'
else:
s[i] = '0'
for i in range(k):
if not S:
break
turn(S)
temp = del0(S)
if temp==1:
k -= i
break
print(S)
print(k)
if k%2==0:
turn(S)
print(''.join(S)) 第二道 6.66%
这过的百分比笑了,自己在线编译没问题:
主要是递归思想,求出最小的。
猜测是递归多了点,栈溢出了吧
a = input() b = input() n1 = len(a) n2 = len(b) c = '' def test(a,b,c): if len(c)>100: return 100 if c not in a and c not in b: return len(c) else: return min(test(a,b,c + '0'),test(a,b,c + '1')) print(min(test(a,b,'0'),test(a,b,'1')))
有大佬知道问题所在吗?
这百分百不知道感觉要凉啊!

全部评论
(6) 回帖