1054: [HAOI2008]移动玩具
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
0000
1110
0010
1010
0101
1010
0101
Sample Output
HINT
Source
题解:其实是一道水水哒搜索题,只要你知道怎么状压,怎么用一个数组判重同时记录最优值就好了
(PS:其实我WA掉的那一次是没特判开头结尾情况完全一样的情形,应该输出0,而我原来的程序将没有输出= =,注意下)
- /**************************************************************
- Problem:
- User: HansBug
- Language: Pascal
- Result: Accepted
- Time: ms
- Memory: kb
- ****************************************************************/
- var
- i,j,k,l,m,n,x0,x1,x,y,f,r:longint;
- c,d:array[..] of longint;
- list:array[..] of longint;ch:char;
- function num(x,y:longint):longint;inline;
- begin
- exit(*(x-)+y);
- end;
- function getit(x,y:longint):longint;inline;
- begin
- if odd(x div list[y]) then exit() else exit();
- end;
- procedure orz(x:longint);inline;
- begin
- writeln(x);
- readln;
- halt;
- end;
- begin
- list[]:=;for i:= to do list[i]:=list[i-]*;
- x0:=;x1:=;
- for i:= to do
- begin
- for j:= to do
- begin
- read(ch);
- inc(x0,(ord(ch)-)*list[num(i,j)]);
- end;
- readln;
- end;
- readln;
- for i:= to do
- begin
- for j:= to do
- begin
- read(ch);
- inc(x1,(ord(ch)-)*list[num(i,j)]);
- end;
- readln;
- end;
- if x0=x1 then orz();
- for i:= to do c[i]:=maxlongint;
- d[]:=x0;f:=;r:=;c[x0]:=;
- while f<r do
- begin
- l:=d[f];i:=;x:=;y:=;
- while l> do
- begin
- x:=x+y div ;y:=y mod +;
- if odd(l) then
- begin
- if x> then
- begin
- if getit(d[f],i-)= then
- begin
- d[r]:=d[f]-list[i]+list[i-];
- if c[d[r]]=maxlongint then
- begin
- c[d[r]]:=c[d[f]]+;
- if d[r]=x1 then orz(c[d[r]]);
- inc(r);
- end;
- end
- end;
- if x< then
- begin
- if getit(d[f],i+)= then
- begin
- d[r]:=d[f]-list[i]+list[i+];
- if c[d[r]]=maxlongint then
- begin
- c[d[r]]:=c[d[f]]+;
- if d[r]=x1 then orz(c[d[r]]);
- inc(r);
- end;
- end;
- end;
- if y> then
- begin
- if getit(d[f],i-)= then
- begin
- d[r]:=d[f]-list[i]+list[i-];
- if c[d[r]]=maxlongint then
- begin
- c[d[r]]:=c[d[f]]+;
- if d[r]=x1 then orz(c[d[r]]);
- inc(r);
- end;
- end;
- end;
- if y< then
- begin
- if getit(d[f],i+)= then
- begin
- d[r]:=d[f]-list[i]+list[i+];
- if c[d[r]]=maxlongint then
- begin
- c[d[r]]:=c[d[f]]+;
- if d[r]=x1 then orz(c[d[r]]);
- inc(r);
- end;
- end;
- end;
- end;
- inc(i);l:=l div ;
- end;
- inc(f);
- end;
- end.
1054: [HAOI2008]移动玩具的更多相关文章
- bzoj 1054: [HAOI2008]移动玩具 bfs
1054: [HAOI2008]移动玩具 Time Limit: 10 Sec Memory Limit: 162 MB[Submit][Status][Discuss] Description 在 ...
- BZOJ 1054 [HAOI2008]移动玩具
1054: [HAOI2008]移动玩具 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1388 Solved: 764[Submit][Statu ...
- 【BZOJ】1054: [HAOI2008]移动玩具(bfs+hash)
http://www.lydsy.com/JudgeOnline/problem.php?id=1054 一开始我还以为要双向广搜....但是很水的数据,不需要了. 直接bfs+hash判重即可. # ...
- 1054: [HAOI2008]移动玩具 - BZOJ
Description 在一个4*4的方框内摆放了若干个相同的玩具,某人想将这些玩具重新摆放成为他心中理想的状态,规定移动时只能将玩具向上下左右四个方向移动,并且移动的位置不能有玩具,请你用最少的移动 ...
- BZOJ 1054: [HAOI2008]移动玩具(bfs)
题面: https://www.lydsy.com/JudgeOnline/problem.php?id=1054 题解: 将每一种状态十六位压成二进制,然后bfs..不解释.. p.s.注意特判初始 ...
- 1054. [HAOI2008]移动玩具【BFS】
Description 在一个4*4的方框内摆放了若干个相同的玩具,某人想将这些玩具重新摆放成为他心中理想的状态,规定移动 时只能将玩具向上下左右四个方向移动,并且移动的位置不能有玩具,请你用最少的移 ...
- bzoj1054: [HAOI2008]移动玩具
hash+bfs:要注意特殊情况.(似乎连sort.lower_bound都不用数据小直接判重了... #include<cstdio> #include<cstring> # ...
- [BZOJ1054][HAOI2008]移动玩具 bfs+hash
1054: [HAOI2008]移动玩具 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2432 Solved: 1355[Submit][Stat ...
- P4289 [HAOI2008]移动玩具(bfs)
P4289 [HAOI2008]移动玩具 双向bfs+状态压缩+记忆化搜索 双向bfs用于对bfs的优化,每次找到可扩展节点少的一边进行一次bfs,找到的第一个互相接触的点即为最短路径 矩阵范围仅4* ...
随机推荐
- 用Zephir编写PHP扩展
自从NodeJS,和Golang出来后,很多人都投奔过去了.不为什么,冲着那牛X的性能.那PHP的性能什么时候能提升一下呢?要不然就会被人鄙视了.其实大牛们也深刻体会到了这些威胁,于是都在秘密开发各种 ...
- 使用 GitHub, Jekyll 打造自己的免费独立博客
使用 GitHub, Jekyll 打造自己的免费独立博客 GitHub是一个代码托管网站,现在很多开源项目都放在GitHub上. 利用GitHub,可以让全球各地的程序员们一起协作开发.GitHub ...
- 用ant打包可运行的jar文件 (将第三方jar包放进你自己的jar包)
http://blog.csdn.net/caiqcong/article/details/7618582 <span style="font-family:SimSun;font-s ...
- Spring MVC URL的映射问题 ;Spring MVC 跳转与iframe包含地址问题
/login/login.html 进行form提交,登录之后的页面位于/main/frame.jsp; 这样的controller中的地址需要映射成/main/login.do,然后在control ...
- 《RDLC部署》RDLC部署到IIS缺少DLL程序集
1.错误:从vs生成网站部署到服务器后打开RDLC报表却提示缺少DLL程序集. 一般是缺少如下文件 1. Microsoft.ReportViewer.Common.dll 2. Microsof ...
- The certificate used to sign "" has either expired or has been revoked.
这句话的意思就是"签名"的证书已过期或已被吊销. 说白了就是有人删除了你的证书,解决的办法就是在创建一个,创建证书有两种办法,. 第一: 在苹果开发者中心,进入自己的账号,请求一个 ...
- Spark:控制日志输出级别
Spark:控制日志输出级别 终端修改 在pySpark终端可使用下面命令来改变日志级别 sc.setLogLevel("WARN") # 或者INFO等 修改日志设置文件 ** ...
- [html5] 学习笔记-表单新增元素与属性
本节讲的是表单元素的form,formaction属性,frommethod,formenctype属性,formtarget,autofocus属性,required,labels属性. 1.for ...
- asp.net权限认证篇外:集成域账号登录
在之前的我们已经讲过asp.net权限认证:Windows认证,现在我们来讲讲域账号登录, 这不是同一件事哦,windows认证更多的是对资源访问的一种权限管控,而域账号登录更多的是针对用户登录的认证 ...
- PHP变量处理之serialize
官方定义: string serialize ( mixed $value ) serialize() 返回字符串,此字符串包含了表示 value 的字节流,可以存储于任何地方.这有利于存储或传递 P ...