起初的想法果然就是一个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. 超过130个你需要了解的vim命令

    基础 :e filename Open filename for edition :w Save file :q Exit Vim :q! Quit without saving :x Write f ...

  2. Stable Matching 稳定匹配 婚姻算法 shapley 算法

    作者:jostree  转载请注明出处 http://www.cnblogs.com/jostree/p/4051286.html 稳定匹配问题:有N男N女,每个人对于异性都一个排名,先需要得到一种稳 ...

  3. Linux FTP服务安装和远程登录失败

    问题:本机VPlayer安装pure-ftpd  ftp服务,通过flashfxp从windows连接出现以下错误: [左] 正在连接到 vmare -> IP=192.168.174.133 ...

  4. trigger

    trigger() 方法触发被选元素的指定事件 <html><head><script type="text/javascript" src=&quo ...

  5. 谈谈我对OAuth的理解

    自己的理解是,OAuth是一种授权标准.   用于为除了用户之外的第三方应用授权,   并且在授权过程中,第三方应用不会接触到用户的任何信息,   授权完成后,第三方应用可访问用户授权范围内的信息. ...

  6. PHP 透明水印生成代码

    PHP 透明水印生成代码,需要的朋友可以参考下. 复制代码代码如下: <?php  /*  * Created on 2010-10-27  * BY QQ542900563  * Copyri ...

  7. 4、Hbase

    1).逻辑模型 Hbase 以表的形式存储数据,每个表由行和列组成,每个列属于一个特定的列族. 表中由行和列确定的存储单元称为一个元素,每个元素保存了同一份数据的多个版本,由时间戳来标识.行健是数据行 ...

  8. OFBiz进阶之环境搭建(eclipse)

    一. 环境准备 1. jdk1.6 下载地址:http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive- ...

  9. MaskedTextBox控件实现输入验证

    Mask属性可以验证用户在文本中输入数据的格式 this.maskedTextBox1.Mask = "000000-00000000-000A";//身份证号码18位 this. ...

  10. Google地图数据算法

    Google Maps与Google Earth中的每个级别的每一副图片都有一个URL,例如下面这幅我们学校的图的地址是http://kh.google.com/kh?v=3&t=trstrq ...