poj 2935 bfs
来源:互联网 发布:软件行业就业前景 编辑:程序博客网 时间:2024/06/08 08:52
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<queue>#include<stack>using namespace std;const int maxn=15;int dir[maxn][maxn],map[maxn][maxn][4],sx,sy,ex,ey;int help[4][2]={1,0,0,1,-1,0,0,-1};char s[4]={'S','E','N','W'};typedef struct {int x,y;}node;void init(){ memset(map,0,sizeof(map)); memset(dir,-1,sizeof(dir));}void solve(){ queue<node> que; node tp={sx,sy};dir[sx][sy]=0; que.push(tp); while(que.size()) { node tmp=que.front(); que.pop(); for(int i=0;i<4;i++) { node tpp={tmp.x+help[i][0],tmp.y+help[i][1]}; if(tpp.x>=1&&tpp.x<=6&&tpp.y>=1&&tpp.y<=6&&dir[tpp.x][tpp.y]==-1&&!map[tmp.x][tmp.y][i]) { que.push(tpp); dir[tpp.x][tpp.y]=i; if(tpp.x==ex&&tpp.y==ey) return; } } }}void prinf(){ stack<int> stc; node now={ex,ey}; while(!(now.x==sx&&now.y==sy)) { int tp=dir[now.x][now.y];stc.push(tp); tp=(tp+2)%4; now.x+=help[tp][0]; now.y+=help[tp][1]; } while(stc.size()) { printf("%c",s[stc.top()]); stc.pop(); }printf("\n");}int main(){ int tx1,ty1,tx2,ty2; while(scanf("%d%d",&sy,&sx)!=EOF&&(sx||sy)) { scanf("%d%d",&ey,&ex); if(sx==ex&&sy==ey) {printf("\n");continue;} init(); for(int i=1;i<=3;i++) { scanf("%d%d%d%d",&ty1,&tx1,&ty2,&tx2); if(tx1==tx2) { if(ty1>ty2) swap(ty1,ty2); while(ty1<ty2) {map[tx1][ty1+1][0]=map[tx1+1][ty1+1][2]=1; ty1++; } } else { if(tx1>tx2) swap(tx1,tx2); while(tx1<tx2) { map[tx1+1][ty1][1]=map[tx1+1][ty1+1][3]=1; tx1++; } } } solve(); prinf(); } return 0;}
0 0
- poj 2935 bfs
- POJ 2935 BFS
- poj 2935 bfs
- poj--2935(bfs+记录路径)
- [BFS] poj
- POJ 2935 Basic Wall Maze BFS
- poj 2935 Basic Wall Maze bfs
- poj 2935 Basic Wall Maze bfs
- POJ 2935 Basic Wall Maze (BFS)
- poj 3626 简单bfs
- POJ 3278 : 经典BFS
- poj 3126 简单bfs
- poj 3278 简单bfs
- poj 2243 bfs
- poj 1856 bfs
- POJ 3697 BFS暴力
- POJ 2251 BFS
- poj 3278 bfs
- 直接控制OSG摄像机移动
- Android AsyncTask原理-源码层分析
- python语言-It's better to ask forgiveness than permission
- 理解程序调用以及由此引出的缓冲区攻击问题
- Redy语法分析--一元运算符(+ - ~)
- poj 2935 bfs
- 结构体总结
- Java 定时任务类Timer源码解析
- PCA算法原理(讲解非常清楚)
- Glide(二)
- java泛型详解
- ViewPagerIndicator
- H.264与MPEG4区别
- Java数据结构和算法-简单排序(2-选择排序)