Problem Description

The 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've seen it. It is constructed with 15 sliding tiles, each with a number from 1 to 15 on it, and all packed into a 4 by 4 frame with one tile missing. Let's call the missing tile 'x'; the object of the puzzle is to arrange the tiles so that they are ordered as:

 1  2  3  4
5 6 7 8
9 10 11 12
13 14 15 x

where the only legal operation is to exchange 'x' with one of the tiles with which it shares an edge. As an example, the following sequence of moves solves a slightly scrambled puzzle:

 1  2  3  4     1  2  3  4     1  2  3  4     1  2  3  4
5 6 7 8 5 6 7 8 5 6 7 8 5 6 7 8
9 x 10 12 9 10 x 12 9 10 11 12 9 10 11 12
13 14 11 15 13 14 11 15 13 14 x 15 13 14 15 x
r-> d-> r->

The letters in the previous row indicate which neighbor of the 'x' tile is swapped with the 'x' tile at each step; legal values are 'r','l','u' and 'd', for right, left, up, and down, respectively.

Not all puzzles can be solved; in 1870, a man named Sam Loyd was famous for distributing an unsolvable version of the puzzle, and

frustrating many people. In fact, all you have to do to make a regular puzzle into an unsolvable one is to swap two tiles (not counting the missing 'x' tile, of course).

In this problem, you will write a program for solving the less well-known 8-puzzle, composed of tiles on a three by three

arrangement.

Input

You will receive, several descriptions of configuration of the 8 puzzle. One description is just a list of the tiles in their initial positions, with the rows listed from top to bottom, and the tiles listed from left to right within a row, where the tiles are represented by numbers 1 to 8, plus 'x'. For example, this puzzle

1 2 3

x 4 6

7 5 8

is described by this list:

1 2 3 x 4 6 7 5 8

Output

You will print to standard output either the word ``unsolvable'', if the puzzle has no solution, or a string consisting entirely of the letters 'r', 'l', 'u' and 'd' that describes a series of moves that produce a solution. The string should include no spaces and start at the beginning of the line. Do not print a blank line between cases.

SampleInput

2  3  4  1  5  x  7  6  8

SampleOutput

ullddrurdllurdruldr
就是给你一个序列,然后要你通过四种移动方式,回到最初的序列,输出答案,题目有SPJ,无需输出最优方法。
这道题可谓是搜索中的精髓了,最开始我就是一个简单的双向搜索,结果TLE了,看了网上的博客加了剪枝之后过了。
但是后来和队友聊这题,发现这道题的解题思路不止一种,队友说有八种

然后找到一篇博客,里面一共讲了八种解法,应该是很全面的。
博客链接:https://www.cnblogs.com/zufezzt/p/5659276.html至于我的代码就没什么好讲的了,确实用双向BFS加剪枝可以AC这道题,但这道题的精髓远远不在于此,也见识到了自己的学识浅薄。我也道不出个所以然,所以这道题我就不详细讲了。
还是那句话以梦为马,不负韶华。

Egiht(八种方法)的更多相关文章

  1. Javascript刷新页面的八种方法

    /** * Javascript刷新页面的八种方法 * 说明一下,jQuery没有发现刷新页面的方法. */ 1 history.go(0) 2 location.reload() 3 locatio ...

  2. Linux 的shell 字符串截取很有用。有八种方法。

    一 Linux 的字符串截取很有用.有八种方法. 假设有变量 var=http://www.linuxidc.com/123.htm 1  # 号截取,删除左边字符,保留右边字符. echo ${va ...

  3. Linux下进程通信的八种方法

    Linux下进程通信的八种方法:管道(pipe),命名管道(FIFO),内存映射(mapped memeory),消息队列(message queue),共享内存(shared memory),信号量 ...

  4. Python 炫技操作:安装包的八种方法,你知道吗?

    本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理 1. 使用 easy_install easy_install 这应该是最古老的包安装方式了,目前基 ...

  5. Python+Selenium自动化-定位页面元素的八种方法

    Python+Selenium自动化-定位页面元素的八种方法   本篇文字主要学习selenium定位页面元素的集中方法,以百度首页为例子. 0.元素定位方法主要有: id定位:find_elemen ...

  6. c/c++测试函数的运行时间(八种方法)

    目前,存在着各种计时函数,一般的处理都是先调用计时函数,记下当前时间tstart,然后处理一段程序,再调用计时函数,记下处理后的时间tend,再tend和tstart做差,就可以得到程序的执行时间,但 ...

  7. selenium java-3 定位元素的八种方法

    web driver提供了八种元素定位的方法: id name class name tag name link text partial link text xpath css selector 如 ...

  8. selenium定位元素的八种方法

    web driver提供了八种元素定位的方法: id, name, class name, tag name, link text, partial link text, xpath, css sel ...

  9. CSS清除浮动八种方法

    在各种浏览器中显示效果也有可能不相同,这样让清除浮动更难了,下面总结8种清除浮动的方法,测试已通过 ie chrome firefox opera,需要的朋友可以参考下 清除浮动是每一个 web前台设 ...

随机推荐

  1. 使用charls抓包微信小程序的解决方案(终极解决,各种坑不怕,亲测可用,不服来战!)

    第一步:使用charles进行https抓包 https://www.jianshu.com/p/7a88617ce80b   使用charles进行https抓包 使用Charles进行HTTPS抓 ...

  2. CF553C Love Triangles(二分图)

    Tyher推的好题. 题意就是给你一些好边一些坏边,其他边随意,让你求符合好坏坏~,或者只包含好好好的三元环的无向图个数. 坏坏的Tyher的题意是这样的. 再翻译得更加透彻一点就是:给你一些0(好边 ...

  3. windows+appium自动化,Desired Capabilities参数填写,查看界面信息

    前言: 安装JDK并配置环境变量. 安装sdk并配置对应环境变量. 安装appium客户端. 手机打开开发者模式,并启用调试模式. 1.打开Appium客户端,点击Start Server V1.9. ...

  4. springboot的异步调用

    package com.handsight.platform.fras.aapp; import java.util.Locale; import org.slf4j.Logger; import o ...

  5. TortoiseGit的NetWork中的Enale proxy Server的作用

    NetWork中的Enale proxy Server 如果是局域网的代码管理需打勾: 如否是网路上的代码管理如:github是,要取消打勾: 否则回报:Couldn't resolve proxy ...

  6. Unity 自定义Inspector面板时的数据持久化问题

    自定义Inspector面板的步骤: Unity内创建自定义的Inspector需要在Asset的任意文件夹下创建一个名字是Editor的文件夹,随后这个文件夹内的cs文件就会被放在vstu生成的Ed ...

  7. 分享:个人APP(非企业资质)的微信登录方案

    目前微信开放平台个人主体类APP不支持开通微信登录,那么个人开发者如何解决微信登录的问题呢?目前有一种替代方案是用微信小程序作为媒介来达到微信登录的目的. 微信小程序的登录无需企业资质,同时登录后返回 ...

  8. Python之读取用户指令和格式化打印

    Python之读取用户指令和格式化打印 一.读取用户指令 当你的程序要接收用户输入的指令时,可以用input函数: name = input("请输入你的名字:") print(& ...

  9. AI资源对接需求汇总:第3期

    更好的阅读体验,请查看首发原文链接:AI资源对接需求汇总:第3期 平台介绍 平台由人工智能领域几个知名原创公众号发起,总读者约25万. 主要面向人工智能领域的从业者,涵盖图像处理.三维计算机视觉.机器 ...

  10. Android进阶之路(1)-详解MVC

    最近因为换工作的原因没有写博客,现在慢慢稳定了,我准备写一些关于Android 进阶的文章,也是为了督促自己学习,大家一起进步! 今天详细的分析一下Android APP架构之一:MVC ### MV ...