补题03——牛客
1.https://ac.nowcoder.com/acm/contest/93218/C
我的方法便是举例,找规律,最后代码如下:
from math import *
for _ in range(int(input())):
n = int(input())
if n <= 2:
print(1)
else:
print(2**int((ceil(log(n,2)))))
解释一下为什么数字为8时还是8呢?因为1000只能与0000异或才会出1100,而取值范围又是【1,n】不包含0,所以1100时候还是8,而1001的时候前面的数字足以异或出来包括8在内的到15的所有数字。可以结合图来理解:
2.https://ac.nowcoder.com/acm/contest/93218/D
这道题数学基础要好才会做出来,用三个系数代表一条直线,代码如下:
import math
for _ in range(int(input())):
k = set()
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
for i in range(n - 1):
for j in range(i + 1, n):
x1, y1 = x[i], y[i]
x2, y2 = x[j], y[j]
a, b, c = 2 * (y1 - y2), 2 * (x1 - x2), ((y1 ** 2 + x1 ** 2) - (y2 ** 2 + x2 ** 2))
s = math.gcd(abs(a), abs(b))
s = math.gcd(s, abs(c))
a //= s
b //= s
c //= s
if a < 0:
a *= -1
b *= -1
c *= -1
elif a == 0:
if b < 0:
a *= -1
b *= -1
c *= -1
elif b == 0:
if c < 0:
a *= -1
b *= -1
c *= -1
k.add((a, b, c))
print(len(k))