hdu1240 bfs 水题

原题链接

思路:水题,直接搜

 #include "map"
#include "queue"
#include "math.h"
#include "stdio.h"
#include "string.h"
#include "iostream"
#include "algorithm"
#define abs(x) x > 0 ? x : -x
#define max(a,b) a > b ? a : b
#define min(a,b) a < b ? a : b using namespace std; int z2,x2,y2,n;
int d[][]= {{,,},{,,},{,,-},{,-,},{,,},{-,,}};
bool Map[][][],vis[][][]; struct Node{
int zz,xx,yy;
int step;
}; void Bfs(int z,int x,int y)
{
memset(vis,,sizeof(vis));
queue<Node>Q;
Node now,next; now.zz = z;
now.xx = x;
now.yy = y;
now.step = ;
vis[z][x][y] = ; Q.push(now); while(!Q.empty())
{
now = Q.front();
Q.pop(); if(now.zz==z2 && now.xx==x2 && now.yy==y2)
{
printf("%d %d\n",n,now.step);
return;
} for(int i=; i<; i++)
{
next.zz = now.zz + d[i][];
next.xx = now.xx + d[i][];
next.yy = now.yy + d[i][];
next.step = now.step + ; if(Map[next.zz][next.xx][next.yy] && !vis[next.zz][next.xx][next.yy])
{
vis[next.zz][next.xx][next.yy] = ;
Q.push(next);
}
}
}
printf("NO ROUTE\n");
} int main()
{
int x1,y1,z1,i,j,k;
char s[],c;
while(~scanf("%s%d",s,&n))
{
memset(Map,,sizeof(Map));
for(i=; i<=n; i++)
for(j=; j<=n; j++)
{
getchar();
for(k=; k<=n; k++)
{
scanf("%c",&c);
if(c=='O')
Map[i][j][k] = ;
if(c=='X')
Map[i][j][k] = ;
}
} scanf("%d%d%d%d%d%d",&x1,&y1,&z1,&x2,&y2,&z2);
z1+=,x1+=,y1+=,z2+=,x2+=,y2+=;
getchar();
gets(s); Bfs(z1,x1,y1);
}
return ;
}
上一篇:Ai-Bot 之WindowsBot方法介绍


下一篇:HDU1698 Just a Hook(线段树&区间覆盖)题解