起初的想法果然就是一个6000000的状态的表示。

但是后面觉得还是太过于幼稚了。

可以看看网上的解释,其实就是先转换位置,然后再改变数字的大小。

 #include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cmath>
using std::swap;
using std::queue;
int const INF = ;
int const N = ;
struct node
{
int num[N];
int pos,step,sta;
}cur,nt;
int vis[N][N][N][N][N][N][N][];
node record[];
int visp[][N]=
{
,,,,,,
,,,,,,
,,,,,,
,,,,,,
,,,,,,
,,,,,,
,,,,,,
,,,,,,
,,,,,,
,,,,,,
};
char start[N+],end1[N+];
int cnt;
void system()
{
char tmp[];
printf("Press 0 to continue\n");
while(scanf("%s",tmp))
{
if(tmp[]=='')break;
}
}
bool judge(node tmp)
{
return vis[tmp.num[]][tmp.num[]][tmp.num[]][tmp.num[]][tmp.num[]][tmp.num[]][tmp.pos][tmp.sta];
}
void CreateVis(node tmp)
{
vis[tmp.num[]][tmp.num[]][tmp.num[]][tmp.num[]][tmp.num[]][tmp.num[]][tmp.pos][tmp.sta]=;
}
void bfs()
{
for(int i=;i<N;i++)cur.num[i]=i;
cur.pos=cur.sta=cur.step=;
CreateVis(cur);
queue<node> q;
q.push(cur);
while(!q.empty())
{
cur=q.front();
q.pop();
for(int i=;i<N;i++)
record[cnt].num[i]=cur.num[i];
record[cnt].step=cur.step;
record[cnt].pos=cur.pos;
record[cnt++].sta=cur.sta;
if(cur.pos>)
{
nt=cur;
nt.step=cur.step+;
swap(nt.num[],nt.num[nt.pos]);
if(!judge(nt))
{
q.push(nt);
CreateVis(nt);
}
}
if(cur.pos<)
{
nt=cur;
nt.pos++;
nt.sta++;
nt.step=cur.step+;
if(!judge(nt))
{
q.push(nt);
CreateVis(nt);
}
nt=cur;
if(nt.sta<)
nt.sta+=;
nt.step=cur.step+;
swap(nt.num[],nt.num[nt.pos]);
if(!judge(nt))
{
q.push(nt);
CreateVis(nt);
}
}
}
}
int Min(int a,int b)
{
return a<b?a:b;
}
int main()
{
cnt=;
memset(vis,,sizeof(vis));
bfs();
while(~scanf("%s %s",start,end1))
{
start[]='\0';
end1[]='\0';
//printf("len=%d\n",len);
for(int i=;i<;i++)
{
start[i]=start[i]-'';
end1[i]=end1[i]-'';
}
int step=,flag,ans=INF;
for(int i=;i<cnt;i++)
{
step=record[i].step;
flag=;
for(int j=;j<N;j++)
{
if(!visp[record[i].sta][j]&&start[record[i].num[j]]!=end1[j])
{
flag=;break;
}
else
step+=abs(start[record[i].num[j]]-end1[j]);
}
if(flag)
ans=Min(ans,step);
}
printf("%d\n",ans);
}
return ;
}

poj 1184 广搜进阶题的更多相关文章

  1. POJ3984 BFS广搜--入门题

    迷宫问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20816   Accepted: 12193 Descriptio ...

  2. POJ 3322(广搜)

    ---恢复内容开始--- http://poj.org/problem?id=3322 题意:http://jandan.net/2008/01/24/bloxorz.html就是这个鬼游戏 我也是郁 ...

  3. hdu 1180(广搜好题)

    诡异的楼梯 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Subm ...

  4. poj 3984:迷宫问题(广搜,入门题)

    迷宫问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7635   Accepted: 4474 Description ...

  5. hdu 2612:Find a way(经典BFS广搜题)

    Find a way Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. poj1426--Find The Multiple(广搜,智商题)

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18527   Accepted: 749 ...

  7. hdu 1253:胜利大逃亡(基础广搜BFS)

    胜利大逃亡 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  8. Eight_pku_1077(广搜).java

    Eight Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21718   Accepted: 9611   Special ...

  9. HDU 2267 How Many People Can Survive(广搜,简单)

    题目 //一道简单的广搜水题 #include<queue> #include<stdio.h> #include<string.h> #include<al ...

随机推荐

  1. How to hide an entry in the Add/Remove Programs applet?

    Original link: http://www.winhelponline.com/articles/15/1/How-to-hide-an-entry-in-the-AddRemove-Prog ...

  2. PHP扩展开发(1):入门

    有关PHP扩展开发的文章.博客已经很多了,比较经典的有: TIPI项目(http://www.php-internals.com/,强烈推荐) <Extending and Embedding ...

  3. QML动态加载组件

    QML中的组件可以重复使用,并且可以通过Loader加载.如下示例: import QtQuick 2.4 import QtQuick.Controls 1.3 import QtQuick.Win ...

  4. tomcat 192.168.1.110?不烦吗?

    最近做一个在线播放器,因为要用到网络服务器做在线播放,又不想直接在本地用tomcat做实验,因为没有真实感. so,手边两台电脑,同时连在局域网. 客户端,笔记本,ip1:192.168.1.101 ...

  5. java中的多线程——进度2

    package src;/*多线程总结:1,进程和线程的概念.    |--进程:    |--线程:2,jvm中的多线程体现.    |--主线程,垃圾回收线程,自定义线程.以及他们运行的代码的位置 ...

  6. SQL注入原理一

    SQL注入的成因 所谓SQL注入,就是通过把SQL命令插入到Web表单提交.页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.根据所注入对象的类型不同,SQL注入分为三类: (1) 变量是 ...

  7. Web应用工作流程总结

    了解Web应用的工作过程有益于Web测试时更好的理解,Web应用工作的过程分为以下5个步骤: 1. 用户在Web浏览器中输入一个Web地址.选择一个超链接或点击一个按钮 2. Web浏览器将用户的动作 ...

  8. 解决Genemotion 安装出现“Unable to start......”的问题

    最近在用uiautomator做安卓自动化测试,由于没有测试设备,所以只好自己在电脑里面安装了一个GenyMotion模拟器,虽然速度不及真机,但是也算能解决大部分的需求. 安装完之后启动出现了以下错 ...

  9. mysql 远程连接 2003 Can't connect to MySQL server (10060)

    mysql server 端的端口被防火墙挡出,没有开放

  10. 微信支付JS API使用心得

    微信的接口真的很坑爹,只返回成功或失败,从来不会告诉你为什么失败.这个微信支付的js接口也是调了一个下午才成功,期间踩了不少坑,在这里总结一下,而且把支付接口封装成了一个js文件,这样以后调用就很方便 ...