P1805 关灯、P2438 [SDOI2005]解环(找规律)

双倍经验,由于要高精所以上了一发python

打表之后上oeis找的规律,a[n]=n^n/2^n/4^...^a/(2^m)

其中2^m<=n

然后是代码:

n=eval(input())
a=[float(n) for n in input().split()]
base=1
ans=0
for i in range(n):
    if a[i]==1:
        ans+=base
    base*=2
#print(ans)
out=0
base=1
while ans>=base:
    out^=ans//base
    base*=2
print(out)

顺便学到了python读取一个数组进来的方法

猜你喜欢

转载自www.cnblogs.com/oneman233/p/11573348.html