题目描述
blablabla
样例
blablabla
算法1
(暴力枚举) $O(2^n)$
暴力枚举找规律
时间复杂度
参考文献
python 代码
for _ in range(2,10):
l = pow(2,_)
r = pow(2,_ + 1)
ans = 0
for i in range(0,r):
f = [int(j) for j in (bin(i)[2:]).zfill(_ + 1)]
cnt = 0
n = len(f)
flag = 1
print(f)
for x in range(n):
hm = f[(x + 1) % n]
back = f[(x + 2) % n]
#如果后面一个为真一个为假
if f[x] == 1:
if not ((hm == 1 and back == 0) or (hm == 0 and back == 1)):
flag = 0
break
else:
if ((hm == 1 and back == 0) or (hm == 0 and back == 1)):
flag = 0
break
cnt += 1
if flag:
ans += cnt
print(ans)
算法2
(暴力枚举) $O(1)$
打表可得n为3的倍数时答案为n * 2否则为n
时间复杂度
参考文献
C++ 代码
for _ in range(int(input())):
n = int(input())
print(n * 2 if n % 3 == 0 else n)