首页 > 商汤 8.20 笔试 研究大类A卷
头像
Derec_
编辑于 2020-08-21 15:22
+ 关注

商汤 8.20 笔试 研究大类A卷

商汤的笔试算法题很简单,40分钟做完。
1. 斐波拉契数列。
n = int(input())

if n == 1:
    print(1)
elif n == 2:
    print(2)
else:
    a = 1
    b = 2
    for i in range(2,n):
        a,b = b,a+b
    print(b) 





2. 给定字符串,问能组成多少个单词‘Good’,每个字符用一次,顺序不能变,比如‘GoodGood’能组成两个,‘GooddooG’只能组成一个这样。
字典解决
 from collections import Counter
s = input()
d = Counter()
res = 0
for c in s:
    if c=='G':
        d['G']+=1
    if c=='o':
        if d['Go']>0:
            d['Goo']+=1
            d['Go']-=1
            continue
        if d['G'] > 0:
            d['Go'] += 1
            d['G'] -= 1
            continue


    if c=='d':
        if d['Goo']>0:
            res+=1
            d['Goo']-=1
# print(d)
print(res)

3. 给定一个矩阵,求其中最长连续上升序列的长度,leetcode原题。
从小到大遍历

N,M = list(map(int,input().split()))
road = []
for i in range(N):
    s = list(map(int,input().split()))
    road.append(s)

tem = []
for i in range(N):
    for j in range(M):
        tem.append([road[i][j],i,j])
tem.sort(key = lambda x:x[0])

state = [[0]*M for _ in range(N)]

for num,i,j in tem:
    up,left,right,down = 0,0,0,0
    if i-1>=0 and road[i-1][j]<num:
        up = state[i-1][j]
    if j+1<=M-1 and road[i][j+1]<num:
        right = state[i][j+1]
    if i+1<=N-1 and road[i+1][j]<num:
        down = state[i+1][j]
    if j-1>=0 and road[i][j-1]<num:
        left = state[i][j-1]
    state[i][j] = 1+max(up,left,right,down)

print(max([max(s) for s in state]))
选择题我很***的忘了查准率和召回率的区别。。

求面试!!!

全部评论

(9) 回帖
加载中...
话题 回帖

推荐话题

相关热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

近期精华帖

热门推荐