1054: [HAOI2008]移动玩具

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 1272  Solved: 690
[Submit][Status][Discuss]

Description

在一个4*4的方框内摆放了若干个相同的玩具,某人想将这些玩具重新摆放成为他心中理想的状态,规定移动时只能将玩具向上下左右四个方向移动,并且移动的位置不能有玩具,请你用最少的移动次数将初始的玩具状态移动到某人心中的目标状态。

Input

前4行表示玩具的初始状态,每行4个数字1或0,1表示方格中放置了玩具,0表示没有放置玩具。接着是一个空行。接下来4行表示玩具的目标状态,每行4个数字1或0,意义同上。

Output

一个整数,所需要的最少移动次数。

Sample Input

1111
0000
1110
0010

1010
0101
1010
0101

Sample Output

4

HINT

 

Source

题解:其实是一道水水哒搜索题,只要你知道怎么状压,怎么用一个数组判重同时记录最优值就好了

(PS:其实我WA掉的那一次是没特判开头结尾情况完全一样的情形,应该输出0,而我原来的程序将没有输出= =,注意下)

  1. /**************************************************************
  2. Problem:
  3. User: HansBug
  4. Language: Pascal
  5. Result: Accepted
  6. Time: ms
  7. Memory: kb
  8. ****************************************************************/
  9.  
  10. var
  11. i,j,k,l,m,n,x0,x1,x,y,f,r:longint;
  12. c,d:array[..] of longint;
  13. list:array[..] of longint;ch:char;
  14. function num(x,y:longint):longint;inline;
  15. begin
  16. exit(*(x-)+y);
  17. end;
  18. function getit(x,y:longint):longint;inline;
  19. begin
  20. if odd(x div list[y]) then exit() else exit();
  21. end;
  22. procedure orz(x:longint);inline;
  23. begin
  24. writeln(x);
  25. readln;
  26. halt;
  27. end;
  28. begin
  29. list[]:=;for i:= to do list[i]:=list[i-]*;
  30. x0:=;x1:=;
  31. for i:= to do
  32. begin
  33. for j:= to do
  34. begin
  35. read(ch);
  36. inc(x0,(ord(ch)-)*list[num(i,j)]);
  37. end;
  38. readln;
  39. end;
  40. readln;
  41. for i:= to do
  42. begin
  43. for j:= to do
  44. begin
  45. read(ch);
  46. inc(x1,(ord(ch)-)*list[num(i,j)]);
  47. end;
  48. readln;
  49. end;
  50. if x0=x1 then orz();
  51. for i:= to do c[i]:=maxlongint;
  52. d[]:=x0;f:=;r:=;c[x0]:=;
  53. while f<r do
  54. begin
  55. l:=d[f];i:=;x:=;y:=;
  56. while l> do
  57. begin
  58. x:=x+y div ;y:=y mod +;
  59. if odd(l) then
  60. begin
  61. if x> then
  62. begin
  63. if getit(d[f],i-)= then
  64. begin
  65. d[r]:=d[f]-list[i]+list[i-];
  66. if c[d[r]]=maxlongint then
  67. begin
  68. c[d[r]]:=c[d[f]]+;
  69. if d[r]=x1 then orz(c[d[r]]);
  70. inc(r);
  71. end;
  72. end
  73. end;
  74. if x< then
  75. begin
  76. if getit(d[f],i+)= then
  77. begin
  78. d[r]:=d[f]-list[i]+list[i+];
  79. if c[d[r]]=maxlongint then
  80. begin
  81. c[d[r]]:=c[d[f]]+;
  82. if d[r]=x1 then orz(c[d[r]]);
  83. inc(r);
  84. end;
  85. end;
  86. end;
  87. if y> then
  88. begin
  89. if getit(d[f],i-)= then
  90. begin
  91. d[r]:=d[f]-list[i]+list[i-];
  92. if c[d[r]]=maxlongint then
  93. begin
  94. c[d[r]]:=c[d[f]]+;
  95. if d[r]=x1 then orz(c[d[r]]);
  96. inc(r);
  97. end;
  98. end;
  99. end;
  100. if y< then
  101. begin
  102. if getit(d[f],i+)= then
  103. begin
  104. d[r]:=d[f]-list[i]+list[i+];
  105. if c[d[r]]=maxlongint then
  106. begin
  107. c[d[r]]:=c[d[f]]+;
  108. if d[r]=x1 then orz(c[d[r]]);
  109. inc(r);
  110. end;
  111. end;
  112. end;
  113. end;
  114. inc(i);l:=l div ;
  115. end;
  116. inc(f);
  117. end;
  118. end.

1054: [HAOI2008]移动玩具的更多相关文章

  1. bzoj 1054: [HAOI2008]移动玩具 bfs

    1054: [HAOI2008]移动玩具 Time Limit: 10 Sec  Memory Limit: 162 MB[Submit][Status][Discuss] Description 在 ...

  2. BZOJ 1054 [HAOI2008]移动玩具

    1054: [HAOI2008]移动玩具 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1388  Solved: 764[Submit][Statu ...

  3. 【BZOJ】1054: [HAOI2008]移动玩具(bfs+hash)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1054 一开始我还以为要双向广搜....但是很水的数据,不需要了. 直接bfs+hash判重即可. # ...

  4. 1054: [HAOI2008]移动玩具 - BZOJ

    Description 在一个4*4的方框内摆放了若干个相同的玩具,某人想将这些玩具重新摆放成为他心中理想的状态,规定移动时只能将玩具向上下左右四个方向移动,并且移动的位置不能有玩具,请你用最少的移动 ...

  5. BZOJ 1054: [HAOI2008]移动玩具(bfs)

    题面: https://www.lydsy.com/JudgeOnline/problem.php?id=1054 题解: 将每一种状态十六位压成二进制,然后bfs..不解释.. p.s.注意特判初始 ...

  6. 1054. [HAOI2008]移动玩具【BFS】

    Description 在一个4*4的方框内摆放了若干个相同的玩具,某人想将这些玩具重新摆放成为他心中理想的状态,规定移动 时只能将玩具向上下左右四个方向移动,并且移动的位置不能有玩具,请你用最少的移 ...

  7. bzoj1054: [HAOI2008]移动玩具

    hash+bfs:要注意特殊情况.(似乎连sort.lower_bound都不用数据小直接判重了... #include<cstdio> #include<cstring> # ...

  8. [BZOJ1054][HAOI2008]移动玩具 bfs+hash

    1054: [HAOI2008]移动玩具 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2432  Solved: 1355[Submit][Stat ...

  9. P4289 [HAOI2008]移动玩具(bfs)

    P4289 [HAOI2008]移动玩具 双向bfs+状态压缩+记忆化搜索 双向bfs用于对bfs的优化,每次找到可扩展节点少的一边进行一次bfs,找到的第一个互相接触的点即为最短路径 矩阵范围仅4* ...

随机推荐

  1. 用Zephir编写PHP扩展

    自从NodeJS,和Golang出来后,很多人都投奔过去了.不为什么,冲着那牛X的性能.那PHP的性能什么时候能提升一下呢?要不然就会被人鄙视了.其实大牛们也深刻体会到了这些威胁,于是都在秘密开发各种 ...

  2. 使用 GitHub, Jekyll 打造自己的免费独立博客

    使用 GitHub, Jekyll 打造自己的免费独立博客 GitHub是一个代码托管网站,现在很多开源项目都放在GitHub上. 利用GitHub,可以让全球各地的程序员们一起协作开发.GitHub ...

  3. 用ant打包可运行的jar文件 (将第三方jar包放进你自己的jar包)

    http://blog.csdn.net/caiqcong/article/details/7618582 <span style="font-family:SimSun;font-s ...

  4. Spring MVC URL的映射问题 ;Spring MVC 跳转与iframe包含地址问题

    /login/login.html 进行form提交,登录之后的页面位于/main/frame.jsp; 这样的controller中的地址需要映射成/main/login.do,然后在control ...

  5. 《RDLC部署》RDLC部署到IIS缺少DLL程序集

    1.错误:从vs生成网站部署到服务器后打开RDLC报表却提示缺少DLL程序集. 一般是缺少如下文件 1. Microsoft.ReportViewer.Common.dll 2.   Microsof ...

  6. The certificate used to sign "" has either expired or has been revoked.

    这句话的意思就是"签名"的证书已过期或已被吊销. 说白了就是有人删除了你的证书,解决的办法就是在创建一个,创建证书有两种办法,. 第一: 在苹果开发者中心,进入自己的账号,请求一个 ...

  7. Spark:控制日志输出级别

    Spark:控制日志输出级别 终端修改 在pySpark终端可使用下面命令来改变日志级别 sc.setLogLevel("WARN") # 或者INFO等 修改日志设置文件 ** ...

  8. [html5] 学习笔记-表单新增元素与属性

    本节讲的是表单元素的form,formaction属性,frommethod,formenctype属性,formtarget,autofocus属性,required,labels属性. 1.for ...

  9. asp.net权限认证篇外:集成域账号登录

    在之前的我们已经讲过asp.net权限认证:Windows认证,现在我们来讲讲域账号登录, 这不是同一件事哦,windows认证更多的是对资源访问的一种权限管控,而域账号登录更多的是针对用户登录的认证 ...

  10. PHP变量处理之serialize

    官方定义: string serialize ( mixed $value ) serialize() 返回字符串,此字符串包含了表示 value 的字节流,可以存储于任何地方.这有利于存储或传递 P ...