首页 > 5月12日美团笔试春招在线笔试+代码分享

5月12日美团笔试春招在线笔试+代码分享

第一题:100 期末考试
第二题:64 汉明距离
第三题:18 灾难预测
第四题:0 字符串匹配
第五题:9 相似度


import sys
if __name__ == "__main__":
    """
    n,m=5,5
    values=[[96 ,35,38 ,10 ,19 ],
[4, 76 ,72, 38 ,86 ],
[95 ,80 ,81 ,17 ,10 ],
[70 ,64 ,86 ,85 ,10 ],
[1 ,93 ,19 ,34 ,41]]
"""
    # 读取第一行的n
    inpu=list(map(lambda x:int(x),list(input().split())))
    n=inpu[0]
    m=inpu[1]
    best=[-1]*m
    index=[[-1]]*m
    price=[0]*n
    ans = 0
    for i in range(n):
        # 读取每一行
        line = sys.stdin.readline().strip()
        # 把每一行的数字分隔后转化成int列表
        values = list(map(int, line.split()))
        for key,v in enumerate(values):
            if v>best[key]:
                best[key]=v
                index[key]=[]
                index[key].append(i)
            elif v==best[key]:
                index[key].append(i)
    print(best)
    print(index)
    for i in range(m):
        if not best[i]==-1:
            for j in range(len(index[i])):
                price[index[i][j]]=1   
    print(price)
    print(sum(price))

n=4
m=5
value=[
[2,4],
[1, 3],
[2, 3],
[1,4],
[2 ,3]]
place=[0]*(n+1)
for i in range(m):
    op,pos=value[i][0],value[i][1]
    if op==1:
        place[pos]=-1
    if op==2:
        flag=0
        for j in range(pos,n+1):
            if place[j]==0:
                print(j)
                flag=1
                break
        if flag==0: print(-1)
        


def Search (a, l, r, x): 
    if r >= l: 
        mid = int(l + (r - l)/2)
        if a[mid] == x: 
            return mid 

        elif a[mid] > x: 
            return Search(a, l, mid-1, x) 
        else: 
            return Search(a, mid+1, r, x) 
    else: 
        return -1
#inpu=list(map(lambda x:int(x),list(input().split())))
#n=inpu[0]
#m=inpu[1]
n=4
m=5
b=0
value=[
[2,4],
[1, 3],
[2, 3],
[1,4],
[2 ,3]]
place=[]
for i in range(m):
    #inpu=list(map(lambda x:int(x),list(input().split())))
    #op,pos=inpu[0],inpu[1]
    op,pos=value[i][0],value[i][1]
    if op==1:
        result = Search(place, 0, len(place)-1, pos) 
        if result==-1:
            place.append(pos)
            b=b+1
    if op==2:
        place=sorted(place)
        flag=0
        if b==n :
            print(-1) 
            continue
        for j in range(pos,n+1):
            result = Search(place, 0, len(place)-1, j) 
            if result==-1:
                print(j)
                flag=1
                break
        if flag==0: print(-1)



#m=list(map(lambda x:int(x),list(input().split())))
#a=list(map(lambda x:int(x),list(input().split())))
m=4
a=[3 ,5, 6 ,1]
ans=[-1]*(m)
for i in range(m):
    if ans[i]==1:
        continue
    for j in range(i+1,m):
        if a[i] & a [j]==0:
            ans[i]=1
            ans[j]=1
for i in range(m):print(ans[i],end=" ")


全部评论

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

推荐话题

相关热帖

近期热帖

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

近期精华帖

热门推荐