标签:time view ott sample 左右移动 ssi recommend std display
http://acm.hdu.edu.cn/showproblem.php?pid=2102
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 30734 Accepted Submission(s): 7694
终点可以在0,0,0...
1 #include<iostream> 2 #include<cstring> 3 #include<cmath> 4 #include<string> 5 #include<queue> 6 #include<cstdio> 7 using namespace std; 8 int n,m,t; 9 struct sair{ 10 int x,y,z,step; 11 }; 12 13 char map[5][15][15]; 14 int book[5][15][15]; 15 int dir[4][2]={0,1,1,0,0,-1,-1,0}; 16 17 bool bfs(){ 18 sair s,e; 19 s.x=0,s.y=0,s.z=0,s.step=0; 20 queue<sair>Q; 21 Q.push(s); 22 book[s.z][s.x][s.y]=1; 23 while(!Q.empty()){ 24 s=Q.front(); 25 Q.pop(); 26 if(map[s.z][s.x][s.y]==‘P‘){ 27 if(t>=s.step){ 28 cout<<"YES"<<endl; 29 return true; 30 } 31 return false; 32 } 33 for(int i=0;i<4;i++){ 34 e.z=s.z; 35 e.x=s.x+dir[i][0]; 36 e.y=s.y+dir[i][1]; 37 if(e.x>=0&&e.x<n&&e.y>=0&&e.y<m&&map[e.z][e.x][e.y]!=‘*‘&&!book[e.z][e.x][e.y]){ 38 book[e.z][e.x][e.y]=1; 39 e.step=s.step+1; 40 if(map[e.z][e.x][e.y]==‘#‘){ 41 e.z^=1; 42 if(map[e.z][e.x][e.y]==‘*‘||map[e.z][e.x][e.y]==‘#‘) continue; 43 } 44 Q.push(e); 45 } 46 } 47 } 48 return false; 49 } 50 51 int main(){ 52 int T; 53 cin>>T; 54 while(T--){ 55 cin>>n>>m>>t; 56 memset(book,0,sizeof(book)); 57 for(int i=0;i<n;i++){ 58 cin>>map[0][i]; 59 } 60 getchar(); 61 for(int i=0;i<n;i++){ 62 cin>>map[1][i]; 63 } 64 if(!bfs()) cout<<"NO"<<endl; 65 } 66 }
标签:time view ott sample 左右移动 ssi recommend std display
原文地址:https://www.cnblogs.com/Fighting-sh/p/9886183.html