网易互娱 9.5游戏开发笔试
以为三道题150分钟绰绰有余,结果第一道题做了一个半小时。
第一题:
n,m=map(int,input().split()) nums=list(map(int,input().split())) ans=[[0] for _ in range(len(nums)+1)] for i in range(len(nums)): ans[i+1][0]=nums[i] for _ in range(m): path,res=[],[] k=int(input()) for _ in range(k): path=list(input().split()) res.append(path) curleft,curright,sum_=[],[],0 for i in range(len(res)): if res[i][0]=='left': if res[i][1]=='take': if len(ans[int(res[i][2])])!=1: curleft.append(ans[int(res[i][2])].pop()) else: curleft.append(ans[int(res[i][2])][0]) elif res[i][1]=='return': ans[int(res[i][2])].append(curleft.pop()) elif res[i][1]=='keep': sum_+=curleft.pop() elif res[i][0]=='right': if res[i][1]=='take': if len(ans[int(res[i][2])])!=1: curright.append(ans[int(res[i][2])].pop()) else: curright.append(ans[int(res[i][2])][0]) elif res[i][1]=='return': ans[int(res[i][2])].append(curright.pop()) elif res[i][1]=='keep': sum_+=curright.pop() if len(curleft)==1: sum_+=curleft.pop() if len(curright)==1: sum_+=curright.pop() print(sum_)