BFS 逃跑的拉尔夫
来源:互联网 发布:淘宝店铺装修店标 编辑:程序博客网 时间:2024/05/01 14:30
#include<stdio.h>#include<stdlib.h>#include<queue>#include<map>#include <stdio.h>#include <string.h>#include<iostream>using namespace std;char map_[55][55];char directs[2010][10];int total_directs;bool flag[55][55][2010];struct hereT{ int x,y,cen;};int height,width;queue<hereT>que;void push_eve(hereT temp){ hereT haha; //cout<<"posi:"<<temp.x<<" "<<temp.y<<"direct:"<<directs[temp.cen]<<endl; if(flag[temp.x][temp.y][temp.cen]==1)return; if(temp.cen>total_directs){map_[temp.x][temp.y]='*';return;} if(directs[temp.cen][0]=='N'){ for(int i=1;;i++){ int newx=temp.x-i,newy=temp.y; if(newx<1)return; if(map_[newx][newy]=='X')return; haha.cen = temp.cen+1; haha.x=newx;haha.y=newy; que.push(haha); flag[temp.x][temp.y][temp.cen]=1; } } else if(directs[temp.cen][0]=='S'){ for(int i=1;;i++){ int newx=temp.x+i,newy=temp.y; if(newx>height)return; if(map_[newx][newy]=='X')return; haha.cen = temp.cen+1; haha.x=newx;haha.y=newy; que.push(haha); flag[temp.x][temp.y][temp.cen]=1; } } else if(directs[temp.cen][0]=='W'){ for(int i=1;;i++){ int newx=temp.x,newy=temp.y-i; if(newy<1)return; if(map_[newx][newy]=='X')return; haha.cen = temp.cen+1; haha.x=newx;haha.y=newy; que.push(haha); flag[temp.x][temp.y][temp.cen]=1; } } else if(directs[temp.cen][0]=='E'){ for(int i=1;;i++){ int newx=temp.x,newy=temp.y+i; if(newy>width)return; if(map_[newx][newy]=='X')return; haha.cen = temp.cen+1; haha.x=newx;haha.y=newy; que.push(haha); flag[temp.x][temp.y][temp.cen]=1; } }}int main(){ memset(flag,0,sizeof(flag)); cin>>height>>width; hereT start; for(int i=1;i<=height;i++){ for(int j=1;j<=width;j++){ cin>>map_[i][j]; if(map_[i][j]=='*'){start.x=i;start.y=j;start.cen=1;} } } /* for(int i=1;i<=height;i++){ for(int j=1;j<=width;j++){ cout<<map_[i][j]; }cout<<endl; }*/ cin>>total_directs; map_[start.x][start.y]='.'; for(int i=1;i<=total_directs;i++)cin>>directs[i]; que.push(start); while(!que.empty()){ start=que.front(); que.pop(); push_eve(start); } for(int i=1;i<=height;i++){ for(int j=1;j<=width;j++){ cout<<map_[i][j]; }cout<<endl; }}
0 0
- BFS 逃跑的拉尔夫
- ACM 1026 逃跑的拉尔夫(BFS)
- 逃跑的拉尔夫---题目建议BFS
- codevs 1026 逃跑的拉尔夫 BFS
- codevs 1026 逃跑的拉尔夫(BFS)
- wikioi-天梯-普及一等-bfs-1026:逃跑的拉尔夫
- codevs 1026 逃跑的拉尔夫(BFS+判重)
- code[vs]1026 逃跑的拉尔夫(bfs+判重)
- 1026 逃跑的拉尔夫
- 1026 逃跑的拉尔夫
- CodevsP1026 逃跑的拉尔夫
- [codevs1026] 逃跑的拉尔夫
- wikioi 逃跑的拉尔夫
- 逃跑的拉尔夫
- Wikioi P1026 逃跑的拉尔夫
- 【wikioi】1026 逃跑的拉尔夫
- wikioi 1026 逃跑的拉尔夫
- 【wikioi】1026逃跑的拉尔夫
- 利用全排列算法八皇后问题和正方体摆数使三组面顶点之和相等问题
- JavaSE知识点
- HDU4864Task 贪心multiset使用
- Android实现全屏显示的方法
- ATS中用到的sscanf高级用法说明
- BFS 逃跑的拉尔夫
- Ajax系列之四:问题总结
- 2004成绩转换
- java小总结
- 第八天 框架之痛-Spring MVC(一)
- primitive原始数据类型
- Wampserver默认mysql密码重置,Wampserver教程,Wampserver安装教程,网站发布外网
- 【leetcode】Candy
- Android 知识点