poj 1475 嵌套bfs
来源:互联网 发布:js判断网址是否存在 编辑:程序博客网 时间:2024/06/14 03:57
#include<iostream>#include<cstdio>#include<cstring>#include<queue>#include<string>using namespace std;int sx,sy,bx,by,tx,ty,r,c,psx,psy,pex,pey,vis_person[25][25],vis_box[25][25],cas;int help[4][2]={0,1,0,-1,1,0,-1,0};char walk[4]={'e','w','s','n'};char push[4]={'E','W','S','N'};typedef struct{ int person_x,person_y,box_x,box_y; string now;} status;struct node{ int sx,sy; string now;};char map[25][25];bool check(int i,int j){ if(i>=0&&i<r&&j>=0&&j<c&&map[i][j]!='#') return true; return false;}string bfs_person(){ memset(vis_person,0,sizeof(vis_person)); node st; st.sx=psx,st.sy=psy,st.now=""; queue<node> que; que.push(st); while(que.size()) { node temp=que.front(); que.pop(); if(temp.sx==pex&&temp.sy==pey) return temp.now; for(int i=0;i<4;i++) { node tp=temp; tp.sx+=help[i][0],tp.sy+=help[i][1]; if(!check(tp.sx,tp.sy)) continue; if(tp.sx==bx&&tp.sy==by) continue; if(vis_person[tp.sx][tp.sy]) continue; tp.now+=walk[i]; que.push(tp); vis_person[tp.sx][tp.sy]=1; } } return "23333";}void bfs_box(){ printf("Maze #%d\n",++cas); memset(vis_box,0,sizeof(vis_box)); status st; st.box_x=bx,st.box_y=by,st.person_x=sx,st.person_y=sy,st.now=""; queue<status> que; que.push(st); while(que.size()) { status now_status=que.front(); que.pop(); if(now_status.box_x==tx&&now_status.box_y==ty) { cout<<now_status.now<<endl; printf("\n"); return; } for(int i=0;i<4;i++) { bx=now_status.box_x,by=now_status.box_y; psx=now_status.person_x,psy=now_status.person_y; pex=now_status.box_x-help[i][0],pey=now_status.box_y-help[i][1]; if(!check(pex,pey)) continue; int bex=now_status.box_x+help[i][0],bey=now_status.box_y+help[i][1]; if(!check(bex,bey)) continue; if(vis_box[bex][bey]) continue; string tptp=bfs_person(); if(tptp=="23333") continue; status hehe; hehe.box_x=bex,hehe.box_y=bey; hehe.person_x=now_status.box_x,hehe.person_y=now_status.box_y; hehe.now=now_status.now+tptp+push[i]; que.push(hehe); vis_box[bex][bey]=1; } } printf("Impossible.\n\n");}int main(){ while(scanf("%d%d",&r,&c)!=EOF&&(r||c)) { for(int i=0;i<r;i++) { scanf("%s",map[i]); for(int j=0;j<c;j++) if(map[i][j]=='S') sx=i,sy=j; else if(map[i][j]=='B') bx=i,by=j; else if(map[i][j]=='T') tx=i,ty=j; } bfs_box(); } return 0;}
0 0
- poj 1475 嵌套bfs
- Pushing Boxes (poj 1475 嵌套bfs)
- POJ 1475 Pushing Boxes(嵌套BFS)
- POJ 1475 Pushing Boxes 嵌套BFS -
- hdu 1254 推箱子/poj 1475 Pushing Boxes(推箱子经典问题,BFS嵌套BFS)
- POJ-1475:Pushing Boxes(嵌套bfs或bfs+A*算法)
- poj 1729 Jack and Jill BFS嵌套,同时进行两个
- POJ-1475-Pushing Boxes(BFS)
- [BFS] poj
- poj 1475 Pushing Boxes(推箱子游戏,bfs+bfs)
- POJ 1475 Pushing Boxes 【A*bfs套bfs】
- hdu1254(嵌套bfs,两次bfs)
- POJ 1475 Pushing Boxes 搜索- 两重BFS
- poj 1475 Pushing Boxes(bfs)
- POJ 1475 Pushing Boxes(BFS)
- POJ 1475 Pushing Boxes(BFS)
- poj 3626 简单bfs
- POJ 3278 : 经典BFS
- android模拟登录后带cookie访问受保护的网站比如学校教务网
- CSS滤镜
- OpenGL ES:EGL接口解析与理解
- Ubuntu下设置默认以root账户登录
- 解决华为手机不显示Log日志
- poj 1475 嵌套bfs
- Spark2.1.0在windows下的单机环境搭建
- vuejs初次学习入门
- android sqlite 数据库创建
- 设置ListView的emptyView
- Jenkins的入门教程:
- retrofit下载大文件注意点和android存储位置
- Groovy入门-语法规范
- 安装home-brew下载失败解决失败