2021 vivo提前批-广告推荐算法工程师
1、 赛题背景:
三道编程题,总时间60分钟,据观测编出一道就会收到offer,凉凉送给自己。
注意:要自己编写输入输出
2、题目
题目1:用一个数列表示土地上的种植情况(数列元素仅由0、1组成,1表示该区域已经种植,0表示未种植),现在请你帮助园艺工作人员,在不影响原有花草的情况下,计算出可新种植的最大花草数目(注意:种植的花草不能相邻)
输入描述:输入的第一行为一个数字,表示土地长度,输入的第二行为一个由0和1组成并以空格分隔的数列,表示土地上目前的种植情况。
相似题目:leetcode:链接https://leetcode-cn.com/problems/can-place-flowers`
class Solution:
def canPlaceFlowers(self, flowerbed: List[int], n: int) -> bool:
flowerbed = [0] + flowerbed +[0]
count = 0
for i in range(1,len(flowerbed)-1,1):
if flowerbed[i-1]==0 and flowerbed[i]==0 and flowerbed[i+1]==0 :
flowerbed[i]=1
count =count +1
return count >= n
题目2:假设存在一个楼层F,当楼层高于F时,手机屏会被摔碎,当楼层不高于F时则不会碎,每次测试时测试人员可以将待测手机从任意一层的位置推出,直到准确的找到F的值,求问给定k台测试手机,最少需要测试多少次才能准确找到F值
输入描述:输入为2个正整数K和N,用空格分隔
相似题目:leetcode(887):链接:https://leetcode-cn.com/problems/super-egg-drop/
class Solution:
def superEggDrop(self, K: int, N: int) -> int:
memo = {}
def dp(k,n):
if (k,n) not in memo:
if n==0:
ans = 0
elif k==1:
ans = n
else:
lo,hi=1,n
while lo+1 < hi:
x= (lo+hi) //2
t1 = dp(k-1,x-1)
t2 = dp(k,n-x)
if t1 < t2:
lo=x
elif t1>t2:
hi=x
else:
lo = hi = x
ans = 1 + min(max(dp(k-1,x-1),dp(k,n-x))
for x in (lo,hi))
memo[k,n] = ans
return memo[k,n]
return dp(K, N)
题目3:vivo原有的制造中心受限于空间等资源,在生产某系列产品时,需要拆分出多个子流水线 来运作。随着2019年全新的智能制造中心的落成,现需将该系列产品的多个子流水线合并为一整条完整的流水线。假设用一个由工序编码组成的有序链表来表示条子流水线,请编程实现合并的功能
输入描述:第一行由一个数字n组成,n<1000,表示有n个子流水线;接下来共有n行,每行由空格分割的-组数字组成,表示子流水线的工序编码;
序编码的大小决定了相对顺序,编码较小的始终在前;工序编码全局有效,多个子流水线上的相同编码始终代表同一工字。
输出描述:合并后的用工序编码表示的完整流水线,各工序编码之间由空格分割。
N = int(input())
data = [list(map(int, input().split())) for i in range(N)]
# N=4
# data=[[2, 4, 8],[3,4,6],[5,8,9,11],[1,6,7,10,12]]
class listnode:
def __init__(self, elem, p=None):
self.elem = elem
self.next = p
res=[]
for i in data:
for j in i:
res.append(j)
res = sorted(res)
head = listnode(0)
cur = head
for i in range(len(res)):
cur.next = listnode(res[i])
cur = cur.next
cur = head.next
while cur is not None:
print(cur.elem, end=' ')
cur = cur.next
3、结束语
自己还是太菜了,仍然需要多多做题,感谢那个陪我一起找工作的人。