hdu 1180 诡异的楼梯
来源:互联网 发布:java实现snmp原理 编辑:程序博客网 时间:2024/06/09 19:09
//楼梯有多个 第一次申请了一个NODE LOUTI 来保存一直没找出哪里错
#include <iostream>
#include <queue>
#include<cstdio>
using namespace std;
char map[21][21];
struct node{
int x,y;
int time;
char c;
};
int sx,sy,dx,dy;
//node louti;
bool hash[21][21];
int dir[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int M,N;
void bfs(int x,int y)
{
memset(hash,false,sizeof(hash));
queue<node> q;
node t,p;
t.x = x;
t.y = y;
t.time = 0;
q.push(t);
hash[t.x][t.y]=true;
while (!q.empty())
{
t=q.front();
q.pop();
if (dx==t.x&&dy==t.y)
{
cout<<t.time<<endl;
break;
}
int i;
for (i=0;i<4;i++)
{
p.x = t.x + dir[i][0];
p.y = t.y + dir[i][1];
if (p.x >=0 && p.x < M && p.y >= 0 && p.y < N && map[p.x][p.y] != '*' && !hash[p.x][p.y])
{
if (map[p.x][p.y]=='.'||map[p.x][p.y]=='T')
{
p.time=t.time+1;
q.push(p);
hash[p.x][p.y]=true;
}
if (map[p.x][p.y] == '-' &&(t.time&1)==0 || map[p.x][p.y]=='|' && t.time&1)
{
if(p.x==t.x)
{
p.y = p.y + p.y-t.y;
p.time=t.time+1;
if (p.x>=0&&p.x<M&&p.y>=0&&p.y<N&&map[p.x][p.y]!='*'&&!hash[p.x][p.y])
{
q.push(p);
hash[p.x][p.y]=true;
}
}
else
{
p.x = p.x + p.x - t.x;
p.y= t.y;
p.time=t.time+2;
q.push(p);
}
}
if (map[p.x][p.y]=='|' && (t.time&1)==0 || map[p.x][p.y] == '-' &&t.time&1)
{
if(p.y==t.y)
{
p.x=p.x+p.x-t.x;
p.time=t.time+1;
if (p.x>=0&&p.x<M&&p.y>=0&&p.y<N&&map[p.x][p.y]!='*'&&!hash[p.x][p.y])
{
q.push(p);
hash[p.x][p.y]=true;
hash[t.x][t.y]=true;
}
}
else
{
p.x=t.x;
p.y = p.y + p.y-t.y;
p.time=t.time + 2;
q.push(p);
}
}
}
}
}
}
int main()
{
int i,j;
while(cin>>M>>N)
{
for(i = 0; i < M; i++)
for(j = 0; j < N; j++)
{
cin>>map[i][j];
if(map[i][j] == 'S')
{
sx = i;
sy = j;
}
else if(map[i][j] == 'T')
{
dx = i;
dy = j;
}
//hash[i][j] = true;
}
bfs(sx,sy);
}
return 0;
}
- hdu 1180 诡异的楼梯
- hdu 1180 诡异的楼梯
- HDU 1180 诡异的楼梯
- Hdu-1180(诡异的楼梯)
- HDU 1180 诡异的楼梯
- hdu 1180 诡异的楼梯
- 诡异的楼梯 hdu 1180
- HDU-1180 诡异的楼梯
- hdu 1180 诡异的楼梯
- hdu 1180诡异的楼梯
- HDU 1180诡异的楼梯
- hdu 1180 诡异的楼梯
- hdu 1180 诡异的楼梯
- HDU 1180 诡异的楼梯
- hdu 1180 诡异的楼梯
- hdu 1180 诡异的楼梯
- HDU 1180 诡异的楼梯
- hdu 1180 诡异的楼梯
- hdu 1026 优先队列 + 路径保存
- Linux常用命令
- PHP的错误信息记录到日志文件中
- 李开复:给创新工场求职者的一封信
- Silverlight - Silverlight for Windows Phone中的Render 线程
- hdu 1180 诡异的楼梯
- BLL4
- asp.net
- asp.net
- VC++卸载后重新安装出现不能建立DCOM user account
- 如何防止网站被挂马?
- 【小阅读^大脑袋】0214 NO.320
- 游戏程序员图书推荐
- 基于Visual C++2010 与office2010开发办公自动化(16)-如何设置新建Word文档属性