20 Jun 2019

SCTF-Maaaaaaze

白给题,查看html源代码发现每个点位的方块有'top', 'bottom', 'left', 'right',表示该点上下左右不能走。直接使用正则表达式提取每个点的坐标及其对应的状态,用1+2+4+8存储,然后以图上每一个点作为初始点深度优先搜索即可,每次更新最大值maxn

特别注意此处dfs会爆栈,需要手动扩栈

交了一次发现错误,意识到可能形成了环,所以还需要+1,结果应该为4056

Maze文件地址Maze.html

import re
import sys
sys.setrecursionlimit(100000)
wyx = [[0 for i in range(100)] for i in range(100)]
vis = [[0 for i in range(100)] for i in range(100)]
with open("Maze.html") as file_object:
    str1 = file_object.read()
    print(str1)
str2 = re.findall(r"<td (.+?);\">&nbsp;</td>", str1)
for i in str2:
	a = re.findall(r"id=\"(.+?)-", i)
	b = re.findall(r"-(.+?)\"", i)
	if 'top' in i:
		wyx[int(a[0])][int(b[0])] += 1
	if 'bottom' in i:
		wyx[int(a[0])][int(b[0])] += 2
	if 'left' in i:
		wyx[int(a[0])][int(b[0])] += 4
	if 'right' in i:
		wyx[int(a[0])][int(b[0])] += 8
maxn = 0

def judge(x, y):
	if x < 0 or x > 99:
		return False
	if y < 0 or y > 99:
		return False
	if vis[x][y] == 1:
		return False
	return True

def dfs(x, y, step):
	global maxn
	maxn = max(maxn, step)
	v = wyx[x][y]
	vis[x][y] = 1
	if v >= 8:
		v -= 8
	else:
		if judge(x, y + 1):
			dfs(x, y + 1, step + 1)
	if v >= 4:
		v -= 4
	else:
		if judge(x, y - 1):
			dfs(x, y - 1, step + 1)
	if v >= 2:
		v -= 2
	else:
		if judge(x + 1, y):
			dfs(x + 1, y, step + 1)
	if v >= 1:
		v -= 1
	else:
		if judge(x - 1, y):
			dfs(x - 1, y, step + 1)
	vis[x][y] = 0

for i in range(100):
	for j in range(100):
		dfs(i, j, 0)
print maxn
import hashlib
print hashlib.md5('4056').digest().encode('hex')

Tags:
0 comments