网易互娱 AI笔试 三道题 2个半小时 ac情况

第一题 贩卖机
第二题 求刷新次数
第三题 到达终点的最少步数
楼主 1:ac  2:0 (太多细节了 真敲不出来) 3:  0.9  (python 被卡常数 很难受)
#网易互娱#
全部评论
第三题 0.9 代码 import heapq T=int(input().strip()) for _ in range(T):     n=int(input().strip())     x,y=0,0     graph={(0,0)}     for i in range(n):         a,b=map(int,input().strip().split())         if b==1:             dx=dy=0             if a==0: dx=-1             elif a==1: dx=1             elif a==2: dy=-1             else:dy=1             x,y=x+dx,y+dy             graph.add((x,y))         if i==n-1:             end=(x,y)     stack=[(0,(0,0))]     used={(0,0)}     while stack:         dis,point=heapq.heappop(stack)         if point==end:             print(dis)             break         for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):             temp=(point[0]+dx,point[1]+dy)             if temp not in used  and  temp in graph:                 used.add(temp)                 heapq.heappush(stack,(dis+1,temp))
1 回复 分享
发布于 2020-09-05 17:20
求 第二题代码
1 回复 分享
发布于 2020-09-05 17:22
可以贴代码学习一下吗
点赞 回复 分享
发布于 2020-09-05 17:18
第一题 ac代码  n,m = map(int,input().split()) value=list(map(int,input().split())) extre=[ [] for i in range(n)] for _ in range(m):     k=int(input())     res=0     left=right=None     for _ in range(k):         do=list(input().split())         if do[1]=="take":             do[2]=int(do[2])-1             temp=0             if extre[do[2]]==[]:                 temp=value[do[2]]             else:                 temp=extre[do[2]].pop()             if do[0]=="left":                 left=temp             else:                 right=temp         elif do[1]=="keep":             if do[0]=="left":                 res+=left                 left=0             else:                 res+=right                 right=0         else:             do[2] = int(do[2])-1             if do[0]=="left":                 extre[do[2]].append(left)                 left=0             else:                 extre[do[2]].append(right)                 right=0     if left:res+=left     if right:res+=right     print(res)
点赞 回复 分享
发布于 2020-09-05 17:20
售货机AC,绘制屏幕0.5,迷宫没写完,跪求面试机会
点赞 回复 分享
发布于 2020-09-05 17:46

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务