标签:desc 测试数据 ems 左右 tin push blog 相对 amp
Problem Description
#include <bits/stdc++.h> using namespace std; int move1[4][2]={-1,0,1,0,0,1,0,-1}; char map1[3][16][16]; int vis[3][16][16]; int c,n,m,t,f,px,py,pz; int check(int z,int x,int y) { if(z>=0&&z<=1&&x>=0&&x<n&&y>=0&&y<m&&!vis[z][x][y]&&map1[z][x][y]!=‘*‘) return 1; return 0; } struct node { int z; int x; int y; int step; }; int bfs() { queue<node>Q; node a,next; a.z=0; a.x=0; a.y=0; a.step=0; Q.push(a); while(!Q.empty()) { a=Q.front(); // cout<<a.z<<" "<<a.x<<" "<<a.y<<endl; // cout<<"step="<<a.step<<endl; if(a.x==px&&a.y==py&&a.z==pz) return 1; Q.pop(); if(map1[a.z][a.x][a.y]==‘#‘) { next.x=a.x; next.y=a.y; next.z=a.z^1; next.step=a.step; if(check(next.z,a.x,a.y)&&next.step<=t) { Q.push(next); vis[next.z][a.x][a.y]=1; } continue; } for(int i=0;i<4;i++) { next.x=a.x+move1[i][0]; next.y=a.y+move1[i][1]; next.z=a.z; next.step=a.step+1; if(check(next.z,next.x,next.y)&&next.step<=t) { vis[next.z][next.x][next.y]=1; Q.push(next); } } } return 0; } int main() { cin>>c; while(c--) { memset(vis,0,sizeof(vis)); f=0; cin>>n>>m>>t; for(int k=0;k<2;k++) { for(int i=0;i<n;i++) { cin>>map1[k][i]; } } for(int k=0;k<2;k++) { for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(map1[k][i][j]==‘P‘) { pz=k; px=i; py=j; break; } } } } if(bfs()) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }
标签:desc 测试数据 ems 左右 tin push blog 相对 amp
原文地址:http://www.cnblogs.com/a249189046/p/6637752.html