Nightmare Ⅱ -双向BFS(待更改)

Nightmare Ⅱ

 HDU - 3085 

#include
using namespace std;
#define maxn 888
char mmp[maxn][maxn];
bool vis1[maxn][maxn];
bool vis2[maxn][maxn];
int ans,n,m,t,cnt,step;
struct node
{
    int x,y;
} boy,girl,ghost[5];
struct head
{
    int x,y,f;
} top,temp;
bool judge(head te,int step)
{
    for(int i=1; i<=2; i++)
        if((abs(te.x-ghost[i].x)+abs(te.y-ghost[i].y))<=(step*2))
            return false;
    if(te.x<0||te.y<0||te.x>n-1||te.y>m-1||mmp[te.x][te.y]=='X'||mmp[te.x][te.y]=='Z')
        return false;
    if(te.f==1&&vis1[te.x][te.y]==1)
        return false;
    if(te.f==2&&vis2[te.x][te.y]==1)
        return false;
    return true;
}
int tog[5][5]= {{1,0},{0,1},{-1,0},{0,-1}};
int bfs()
{
    step=0;
    queueqb,qg,qc,qd;
    qb.push((head)
    {
        boy.x,boy.y,1
    });
    qg.push((head)
    {
        girl.x,girl.y,2
    });
    vis1[boy.x][boy.y]=1;
    vis2[girl.x][girl.y]=1;
    if(boy.x==girl.x&&boy.y==girl.y)
        return 0;
    while(!qb.empty()&&!qg.empty())
    {
        step++;
        for(int j=0; j<3; j++)
        {
            qc=qb;
            while(!qb.empty())
                qb.pop();
            while(!qc.empty())
            {
                top=qc.front();
                qc.pop();
                if(vis2[top.x][top.y]==1)
                {
//                    cout<<" "<>t;
    while(t--)
    {
        cnt=0;
        cin>>n>>m;
        for(int i=0; i>mmp[i][j];
                if(mmp[i][j]=='Z')
                {
                    ghost[++cnt].x=i;
                    ghost[cnt].y=j;
//                    cout<

 

你可能感兴趣的:(搜索进阶)