第三题 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))

相关推荐

2025-12-14 11:43
黑龙江大学 Java
用微笑面对困难:确实比较烂,可以这么修改:加上大学的qs排名,然后大学简介要写一些,然后硕士大学加大加粗,科研经历第一句话都写上在复旦大学时,主要负责xxxx,简历左上角把学校logo写上,建议用复旦大学的简历模板
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务