A计划
来源:互联网 发布:php include 路径 编辑:程序博客网 时间:2024/04/28 00:51
#include<iostream>
#include<cstring>#include<queue>
using namespace std;
char map[2][25][25]; //上下两层
bool visited[2][25][25];
int N,M,T;
int d[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
struct node{
int x,y,z,time;
};
void bfs(){
queue<node>q;
node current,temp;
temp.x=temp.y=temp.z=temp.time=0;
q.push(temp);
visited[temp.x][temp.y][temp.z]=true;
while(!q.empty()){
current=q.front();
q.pop();
for(int i=0;i<4;i++){
int x=current.x;
int y=current.y+d[i][0];
int z=current.z+d[i][1];
if(y>=0 && y<N && z>=0 && z<M && !visited[x][y][z] && map[x][y][z]!='*'){
temp.x=x; temp.y=y; temp.z=z;
if(map[temp.x][temp.y][temp.z]=='#'){
visited[temp.x][temp.y][temp.z]=true;
if(temp.x==0)
temp.x=1;
else
temp.x=0;
}
visited[x][y][z]=true;
temp.time=current.time+1;
if(temp.time>T){
cout<<"NO"<<endl;
return ;
}
else if(map[temp.x][temp.y][temp.z]=='P'){
cout<<"YES"<<endl;
return ;
}
q.push(temp);
}
}
}
cout<<"NO"<<endl; //这一步别忘记了,队列空了就表示没有找到亲爱的公主
}
int main(){
int c;
cin>>c;
while(c--){
cin>>N>>M>>T;
for(int i=0;i<2;i++)
for(int j=0;j<N;j++)
for(int k=0;k<M;k++)
cin>>map[i][j][k];
for(int i=0;i<N;i++) //搜索两层
for(int j=0;j<M;j++){
if(map[0][i][j]=='#' && map[1][i][j]=='#')//上下两层都是传输机,则置为墙壁
map[0][i][j]=map[1][i][j]='*';
else if(map[0][i][j]=='#' && map[1][i][j]=='*')
map[0][i][j]=map[1][i][j]='*';
else if(map[0][i][j]=='*' && map[1][i][j]=='#')
map[0][i][j]=map[1][i][j]='*';
}
memset(visited,false,sizeof(visited));
bfs();
}
//system("pause");
return 0;
}
- A计划
- A计划
- A计划
- A计划
- A计划
- A计划
- A计划
- A计划
- A计划
- A计划
- A计划
- A计划
- A计划
- A计划
- A计划
- A - A计划
- 飞行游戏A计划
- A START 计划
- Air flex 读/写文件
- RBAC 权限标准到底讲了啥?有啥啥理念?什么什么版本?中文资料?英文资料?标准例子程序等?
- 扩展Ext的Combobox实现多选下拉列表
- session接口及其常用方法
- 算法与数据结构-单源最短路径之Dijkstra
- A计划
- 草稿
- 弹出界面eth0:错误:激活连接失败:device not managed by NetworkManager
- SYSCALL_DEFINE含义
- VC++简单类示例
- 某时贫的嘴
- 解决UNICODE字符集下CStdioFile的Writestring无法写入中文的问题
- 纯 CSS 的多级菜单
- ImageView的属性android:scaleType