python答案错误_错误答案Python3.6

You are given a set S and Q queries. Initially, S is empty. In each query:

You are given a positive integer X.

You should insert X into S.

For each y∈S before this query such that y≠X, you should also insert y⊕X into S (⊕ denotes the XOR operation).

Then, you should find two values E and O: the number of elements of S with an even number of 1's and with an odd number of 1's in the binary representation, respectively.

我尝试过将问题分解成更小的子问题,但由于输入大小和列表大小都很大,这似乎超出了时间。任何对代码的建议和进一步的优化都将非常有帮助。我已经使用了set,但是预期的输出与我的输出不一样。有没有关于我在解决方案代码中出错的地方的建议。。?在s=set()

def fun(n,q):

c=0

cc=0

s.add(n)

for k in range(len(list(s))):

if list(s)[k]!=n:

s.add((list(s)[k])^n)

for k in s:

if bin(k)[2::].count('1')%2==0:

c+=1

else:

cc+=1

print(c,cc)

for _ in range(int(input())):

q=int(input())

for j in range(q):

n=int(input())

fun(n,q)

输入示例:

^{pr2}$

输出示例:0 1

1 2

3 4

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值