Powered by:AB_IN 局外人
A Ahahahahahahahaha
题目突破点是在于
的值,
.这告诉我们最多删一半。
那这个题就好做了,因为这个串只由
和
组成。
- 当 的数量 的数量,把 删光,不用管 的奇偶。
- 当 的数量 的数量,把 删光, 必须为偶数。
- 当 的数量 的数量,随便删。
for _ in range(int(input())):
n=int(input())
lst=input().split()
one=lst.count("1")
zero=lst.count("0")
if one>zero:
lst=list(filter(lambda x: x=="1",lst))
if len(lst)&1:
lst.pop()
else:
lst=list(filter(lambda x: x=="0",lst))
print(len(lst))
print(" ".join(lst))
B Big Vova
from math import gcd
当只用这个库的一个函数时比较方便。- 还是再记一下
函数对包含元组的列表的应用。
如
lst=[(1,2,3) , (3,1,2) ,(2,10000,2200)]
lst.sort()
print(max(lst))
print(max(lst,key=lambda x: x[1]))
print(min(lst))
print(*lst)
#(3, 1, 2)
#(2, 10000, 2200)
#(1, 2, 3)
#(1, 2, 3) (2, 10000, 2200) (3, 1, 2)
可以看出,默认元组之间的大小比较是根据元组的第一个元素决定的
如果需要更改则在后面加限制条件即可。
- 再说这个题,第一个数一定是最大的数。然后就找与这个数 最大的数。再把这两个数的 和别的数比,挑最大的。以此类推,直到列表为空。
from math import gcd
for _ in range(int(input())):
n=int(input())
lst=list(map(int,input().split()))
maxn=max(lst)
ans=[]
while lst:
tmp = max((gcd(maxn,i),i) for i in lst)
lst.remove(tmp[1])
ans.append(tmp[1])
maxn = tmp[0]
print(*ans)
完结。