蚂蚁 9.22 笔试
6单选 + 不定项选择 + 3编程
编程1是送分题 有两个数a和b,每次可以对一个数乘以2,可以操作两次,问操作后两数和的期望
编程2 一个数每次可以去掉一个数位,但是去掉之后必须保证数字大于0,且是3的倍数,问最多能操作多少次
编程3 嘤嘤的长城,和之前网易的题很像,不过最后也只过了45%,时间也来不及了...
字符串,[1,4,1,4,1,4]为长城字符串,每次可以对其中一个数字加一或减一,问最少需要操作多少次可以成为长城串
T = int(input())
while True:
try:
n = int(input())
nums = list(map(int,input().strip().split()))
odd_count = []
new_count = []
res = 0
for i in range(n):
if i % 2 == 0:
odd_count.append(nums[i])
else:
new_count.append(nums[i])
odd_count = sorted(odd_count)
new_count = sorted(new_count)
ii = (len(odd_count)) // 2
jj = len(new_count) // 2
for i in range(n):
if i % 2 == 0:
res += abs(odd_count[ii] - nums[i])
else:
res += abs(new_count[jj] - nums[i])
print(res)
except:
break
查看17道真题和解析