标签:
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11187 Accepted Submission(s): 2728
题目不难,但是有点坑,因为有个地方忘了被坑去了5次wa,哭晕在厕所。
#include<iostream> #include<queue> #include<cstring> #include<cstdio> using namespace std; char map[2][15][15]; int mark[2][15][15]; int dx[4]={0,0,1,-1}; int dy[4]={1,-1,0,0}; struct Fly { int i,j,k; }fly[450]; struct mi { int i,j,k,time; }; int cas; int n,m,t; void init() { int sum=0; 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]; if(map[i][j][k]==‘#‘) { fly[sum].i=i; fly[sum].j=j; fly[sum].k=k; sum++; } } } } for(int i=0;i<sum;i++) { if(map[1-fly[i].i][fly[i].j][fly[i].k]==‘*‘||map[1-fly[i].i][fly[i].j][fly[i].k]==‘#‘) map[fly[i].i][fly[i].j][fly[i].k]=map[1-fly[i].i][fly[i].j][fly[i].k]=‘*‘; } } void search() { memset(mark,0,sizeof(mark)); mi temp,temp2; temp.i=temp.j=temp.k=temp.time=0; mark[0][0][0]=1; queue<mi>q; q.push(temp); while(!q.empty()) { temp=q.front(); q.pop(); if(temp.time==t) { cout<<"NO"<<endl; return; } temp2.time=temp.time+1; for(int i=0;i<4;i++) { temp2.i=temp.i; temp2.j=temp.j+dx[i]; temp2.k=temp.k+dy[i]; if(temp2.j>=0&&temp2.j<n&&temp2.k>=0&&temp2.k<m&&map[temp2.i][temp2.j][temp2.k]!=‘*‘&&!mark[temp2.i][temp2.j][temp2.k]) { mark[temp2.i][temp2.j][temp2.k]=1; if(map[temp2.i][temp2.j][temp2.k]==‘#‘) { temp2.i=1-temp2.i; if(mark[temp2.i][temp2.j][temp2.k])continue; else mark[temp2.i][temp2.j][temp2.k]=1; } if(map[temp2.i][temp2.j][temp2.k]==‘P‘) { cout<<"YES"<<endl; return; } q.push(temp2); } } } cout<<"NO"<<endl; } int main() { cin>>cas; while(cas--) { init(); search(); } return 0; }
标签:
原文地址:http://www.cnblogs.com/lthb/p/4409425.html