腾讯笔试,综合后台 100-100-0-100-20
1 电话 ac
import sys
t = int(sys.stdin.readline().strip())
for _ in range(t):
n = int(sys.stdin.readline().strip())
line = sys.stdin.readline().strip()
if n < 11:
print('NO')
continue
else:
for c in line:
if n < 11:
print('NO')
break
if c == '8':
print('YES')
break
else:
n -= 1
2 配对 ac import sys
t = int(sys.stdin.readline().strip())
time_list = []
time_dict = {}
for _ in range(t):
line = sys.stdin.readline().strip()
nlist = list(map(int, line.split()))
n = nlist[0]
time = nlist[1]
time_list.append(time)
time_dict[time] = n
time_list.sort()
i = 0
j = len(time_list) - 1
max_sum = 0
while i < j:
curr_sum = time_list[i] + time_list[j]
max_sum = max(curr_sum, max_sum)
if time_dict[time_list[i]] < time_dict[time_list[j]]:
time_dict[time_list[j]] -= time_dict[time_list[i]]
i += 1
elif time_dict[time_list[i]] > time_dict[time_list[j]]:
time_dict[time_list[i]] -= time_dict[time_list[j]]
j -= 1
else:
i += 1
j -= 1
print(max_sum) 3 0 https://zhuanlan.zhihu.com/p/20038650 maybe this? 4 减去最小数 ac
import sys line = sys.stdin.readline().strip() nlist = list(map(int, line.split())) n = nlist[0] k = nlist[1] line = sys.stdin.readline().strip() nlist = list(map(int, line.split())) nlist.sort() res = 0 i = 0 for _ in range(k): if i > n - 1: print(0) else: while nlist[i] - res <= 0: i += 1 if i > n - 1: break if i <= n - 1: print(nlist[i] - res) res += nlist[i] - res i += 1 else: print(0)5 异或 20% 就不插代码了,后来有思路没时间了。
