hdu 1043 八数码 经典搜索问题 BFS+MAP (二)

2014-11-24 01:38:48 · 作者: · 浏览: 5
s+3]=temp.str[pos];
mid[pos]=temp.str[pos+3];
q.pos=pos+3;
}
else if(i==1)
{
mid[pos-3]=temp.str[pos];
mid[pos]=temp.str[pos-3];
q.pos =pos-3;//
}
else if(i==2)
{
mid[pos+1]=temp.str[pos];
mid[pos]=temp.str[pos+1];
q.pos =pos+1;
}
else
{
mid[pos-1]=temp.str[pos];
mid[pos]=temp.str[pos-1];
q.pos =pos-1;
}

if(mp[mid].pos==0)
{
q.path=temp.path;
q.path+=fx[i];
q.str=mid;
mp[mid].path=q.path;
mp[mid].pos=1;
que.push(q);
}
}
}

}
int main()
{
int i ,cnt=0;
char s[2];
begin="12345678x";
pos=8;
BFS();
begin="";
while(scanf("%s",s)!=EOF)
{
cnt++;
begin+=s[0];
if(cnt==9)
{
if(mp[begin].pos==0)
printf("unsolvable\n");
else
{
for(i=mp[begin].path.size()-1;i>=0;i--)
printf("%c",mp[begin].path[i]);
printf("\n");
}
begin="";cnt=0;
}
}

return 0;