起初的想法果然就是一个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. ACM学习

    转:ACM大量习题题库   ACM大量习题题库 现在网上有许多题库,大多是可以在线评测,所以叫做Online Judge.除了USACO是为IOI准备外,其余几乎全部是大学的ACM竞赛题库.   US ...

  2. 抽象工厂(Abstract Factory)模式

    一.抽象工厂(Abstract Factory)模式 抽象工厂模式是所有形态的工厂模式中最为抽象和最具一般性的一种形态. 为了方便引进抽象工厂模式,引进一个新概念:产品族(Product Family ...

  3. IOPS和Throughput

    IOPS和Throughput吞吐量两个参数是衡量存储性能的主要指标.IOPS表示存储每秒传输IO的数量,Throughput吞吐量则表示每秒数据的传输总量.两者在不同的情况下都能表示存储的性能状况, ...

  4. Make和Makefile

    无论是在Linux还是在Unix环境中,make都是一个非常重要的编译命令.不管是自己进行项目开发还是安装应用软件,我们都经常要用到make或make install.利用make工具,我们可以将大型 ...

  5. ACE 6.2.0 win7_64 编译

    Windows平台 ~ Microsoft Visual Studio 1)        下载ACE源码 ACE官方网址:http://www.cs.wustl.edu/~schmidt/ACE.h ...

  6. Python中map,filter,reduce,zip的应用

    事例1: l=[('main', 'router_115.236.xx.xx', [{'abc': 1}, {'dfg': 1}]), ('main', 'router_183.61.xx.xx', ...

  7. 一步步学习ASP.NET MVC3 (12)——FileResult

    请注明转载地址:http://www.cnblogs.com/arhat 忙了两天,本来老魏昨天就应该写出新的文章,但是由于昨天雨夹雪而且加上昨天晚上加了班,到家都没饭吃了,一看时间都9点了,什么饭店 ...

  8. jquery set selected for select element

    //1$("#Provider_" + counter + " option[value=" + FormData.ID + "]").at ...

  9. single page

    http://msdn.microsoft.com/zh-cn/magazine/cc507641.aspx#S7 http://blog.nodejitsu.com/scaling-isomorph ...

  10. Javascript编程模式(JavaScript Programming Patterns)Part 2.(高级篇)

    模块编程模式的启示(Revealing Module Pattern) 客户端对象(Custom Objects) 懒函数定义(Lazy Function Definition) Christian  ...