美文网首页
Python Challenge[24]

Python Challenge[24]

作者: Recgat | 来源:发表于2017-02-26 15:18 被阅读0次

[Level 24]


Title: from top to bottom

困惑了很久,这真是迷宫,from top to bottom。但找出的路径图并没有提供有效信息,需要把像素中的R值用二进制写入文件。注意写入的姿势,前两位数据是PK

某大神使用BFS算法寻路。

from PIL import Image
img = Image.open('maze.png')
dire = [(0,1),(0,-1),(1,0),(-1,0)]
entrance, exit = (639,0), (1,640)
white = (255,255,255,255)
queue = [exit]
next_p = {}

while queue:
  pos = queue.pop(0)
  if pos==entrance:
    break
  for d in dire:
    temp=(pos[0]+d[0],pos[1]+d[1])
    if temp not in next_p and 0<=temp[0]<img.size[0] and 0<=temp[1]<img.size[1] and img.getpixel(temp)!=white:
      next_p[temp] = pos
      queue.append(temp)

按顺序取出数据,再按正确的姿势写入文件:

path = []
while pos!=exit:
  path.append(img.getpixel(pos)[0])
  pos = next_p[pos]
open('maze.zip','wb').write(bytes(path[1::2]))

打开 maze.zip 里的 maze.jpg,涂有lake[Level 25]

Python Challenge Wiki

相关文章

  • Python Challenge[24]

    [Level 24] Title: from top to bottom 困惑了很久,这真是迷宫,from top...

  • Python挑战:00~03关

    Python Challenge Python Challenge 00 网址: http://www.pytho...

  • Python挑战:04-05关

    Python Challenge Python Challenge 04 现在,我们来挑战第四关,从第三关的结果,...

  • The Python Challenge(5)

    问题链接 问题链接如下: 答案链接 答案链接如下: 解题思路 根据页面源码提示: 再点击页面图片显示: 可知是需要...

  • The Python Challenge(8)

    问题链接 问题链接如下: 答案链接 答案链接如下: 解题思路 页面和源码中无任何提示,但图片中有一条很明显的灰度线...

  • The Python Challenge(9)

    问题链接 问题链接如下: 答案链接 答案链接如下: 登陆用户名密码为huge和file。 解题思路 阅读源码有如下...

  • The Python Challenge(2)

    问题链接 问题链接如下: 答案链接 答案链接如下: 解题思路 将页面给定的字符串根据给定规则进行替换即可,规则如下...

  • The Python Challenge(3)

    问题链接 问题链接如下: 答案链接 答案链接如下: 解题思路 根据页面提示: 阅读源码,有如下内容: 编写代码从中...

  • The Python Challenge(4)

    问题链接 问题链接如下: 答案链接 答案链接如下: 解题思路 根据页面提示: 并结合页面源码中的内容,有如下代码:...

  • The Python Challenge(6)

    问题链接 问题链接如下: 答案链接 答案链接如下: 解题思路 根据页面源码提示: python中发音类似的术语有p...

网友评论

      本文标题:Python Challenge[24]

      本文链接:https://www.haomeiwen.com/subject/mnovwttx.html