标签:source tle arch chmod ... other space -- while
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 20023 Accepted Submission(s): 5077
1 //2017-03-02 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 #include <queue> 6 7 using namespace std; 8 9 struct node 10 { 11 int level, x, y, step; 12 void setNode(int l, int x, int y, int s){ 13 this->level = l; 14 this->x = x; 15 this->y = y; 16 this->step = s; 17 } 18 }; 19 char maze[2][15][15]; 20 bool vis[2][15][15]; 21 int dx[4] = {0, 1, 0, -1}; 22 int dy[4] = {1, 0, -1, 0}; 23 24 int main() 25 { 26 int C, T, n, m; 27 cin>>C; 28 while(C--) 29 { 30 cin>>n>>m>>T; 31 node tmp; 32 memset(vis, 0, sizeof(vis)); 33 queue<node> q; 34 for(int level = 0; level < 2; level++) 35 for(int i = 0; i < n; i++) 36 for(int j = 0; j < m; j++){ 37 cin>>maze[level][i][j]; 38 if(maze[level][i][j]==‘S‘){ 39 tmp.setNode(level, i, j, 0); 40 q.push(tmp); 41 vis[level][i][j] = 1; 42 } 43 } 44 int l, x, y, step, ans; 45 bool fg = false; 46 while(!q.empty()) 47 { 48 l = q.front().level; 49 x = q.front().x; 50 y = q.front().y; 51 step = q.front().step; 52 if(step>T)break; 53 q.pop(); 54 if(maze[l][x][y]==‘P‘){ 55 fg = true; 56 break; 57 } 58 for(int i = 0; i < 4; i++) 59 { 60 int nx = x + dx[i]; 61 int ny = y + dy[i]; 62 if(nx>=0&&nx<n&&ny>=0&&ny<m&&!vis[l][nx][ny]&&maze[l][nx][ny]!=‘*‘) 63 { 64 if(maze[l][nx][ny]==‘#‘){ 65 if(maze[l^1][nx][ny]!=‘*‘ && maze[l^1][nx][ny]!=‘#‘){ 66 vis[l][nx][ny] = 1; 67 vis[l^1][nx][ny] = 1; 68 tmp.setNode(l^1, nx, ny, step+1); 69 q.push(tmp); 70 } 71 }else{ 72 vis[l][nx][ny] = 1; 73 tmp.setNode(l, nx, ny, step+1); 74 q.push(tmp); 75 } 76 } 77 } 78 if(fg)break; 79 } 80 if(fg)cout<<"YES"<<endl; 81 else cout<<"NO"<<endl; 82 } 83 84 return 0; 85 }
标签:source tle arch chmod ... other space -- while
原文地址:http://www.cnblogs.com/Penn000/p/6491922.html