1. 直接判断
t = int(input())
def run():
n = int(input())
a = list(map(int, input().split()))
if n % 2 != 0:
return True
x = []
y = []
for i in range(len(a)):
if i % 2 == 0:
x.append(a[i])
else:
y.append(a[i])
x = list(reversed(sorted(x)))
y = list(reversed(sorted(y)))
a = [0]
while len(x) > 0 or len(y) > 0:
if len(x) > 0:
t = x.pop()
if t < a[-1]:
return False
a.append(t)
if len(y) > 0:
t = y.pop()
if t < a[-1]:
return False
a.append(t)
return True
for _ in range(t):
if run():
print("YES")
else:
print("NO")
2. 直接哈希表
n = int(input())
d = {}
for _ in range(n):
s = str(sorted(input()))
if s not in d:
d[s] = 1
else:
d[s] += 1
result = 0
for e in d.values():
result += (e * (e - 1)) // 2
print(result)
3. 直接计算
m = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
s = 0
for i in a:
s += i
mod = n * m
s %= mod
f = 1
for _ in range(n):
f = f * 2
f %= mod
f = (f + mod - 1) % mod
u = (f * s) % mod
if u % n == 0:
print(u // n)
else:
u %= m
n %= m
for i in range(1, 10**6):
t = (u + (i * m))
if t % n == 0:
print(t // n)
break
4. 暴力,TLE 了
#网易校招##笔试#