加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

4.迷宫大逃亡

发布时间:2020-12-20 12:43:12 所属栏目:Python 来源:网络整理
导读:# coding=utf-8 import threading import time import base64 def openfile(): result = "" f = open(r"E:PythonMyScript实验吧in.txt","r") i=int(f.readline().strip()) while (i != 0): line=None while not line: line = f.readline().strip() scale

# coding=utf-8
import threading
import time
import base64
def openfile():
result = ""
f = open(r"E:PythonMyScript实验吧in.txt","r")
i=int(f.readline().strip())
while (i != 0):
line=None
while not line:
line = f.readline().strip()
scale = int(line)
start = []
for x in f.readline().strip().split():
start.append(int(x)-1)
end = []
for x in f.readline().strip().split():
end.append(int(x)-1)
migong = []
for _ in range(scale):
migong.append(f.readline().strip())
r=pyqueue(len(migong[0]),start,end,migong)
result+=str(r.run())
i = i - 1
#print result
print(result)
flag=""
for i in range(0,len(result),8):
c = result[i:i+8]
flag+=chr(int(c,2))
print(base64.b64decode(flag))
class pyqueue:
def __init__(self,_len,_start,_end,_migong):
self.len = _len #地图尺寸
self.start = _start #起点
self.end = _end #终点点 格式 [x,y]
self.migong = _migong #地图
self.queue = [self.start] #初始的地方
self.steptrace = [] #走过的地方
self.sucess = 0 #判断找到了终点
def Iqueue(self,location):
self.queue.append(location)
self.steptrace.append(location)

def Oqueue(self):
temp = self.queue[0]
del (self.queue[0])
return temp

def Void(self,location):
try:
if location in self.steptrace or self.migong[location[0]][location[1]] == "X":
return
else:
if location == self.end:
self.sucess=1
return
self.steptrace.append(location)
self.Iqueue(location)
return
except:
print("error")
print(location)

def empty(self):
try:
self.queue[0]
return True
except IndexError:
return False

def addx(self,x):
x += 1
if x >= self.len: return x - 1
return x

def subx(self,x):
x -= 1
if x < 0: return x + 1
return x

def run(self):
return str(self.zoumigong())

def zoumigong(self):
while self.empty():
location = self.Oqueue()
#print location
self.Void([self.addx(location[0]),location[1]])
self.Void([self.subx(location[0]),location[1]])
self.Void([location[0],self.addx(location[1])])
self.Void([location[0],self.subx(location[1])])
# 上下左右各试探一下
if self.sucess==1:
return 1
return 0

# localtion=[x,y]
# migong[location[0],local[1]]

if __name__ == ‘__main__‘: openfile()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读