# hdu 2102

1、忽视了可以从2层下到1层

2、当扫描到传送机时，将传送机以及另一层相应位置上的点一齐赋值并将该点入队而忘记判断那个点是不是已经访问过。

如果骑士们能够在T时刻能找到公主就输出“YES”，否则输出“NO”。

#include <iostream>
#include <cstring>
#include <queue>
using namespace std;

const int inf = 0x3f3f3f3f;
struct Point{
int f, x, y;
};
int dir[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
char g[2][15][15];
int cnt[2][15][15];
int n, m;

bool judge(int x, int y){
return 0 <= x && x < n && 0 <= y && y < m;
}

void bfs(Point p){
queue <Point> q;
q. push(p);
cnt[p. f][p. x][p. y] = 0;
while(! q. empty()){
Point t = q. front();
q. pop();
int nx, ny;
for(int i = 0; i < 4; i ++){
nx = t. x + dir[i][0], ny = t. y + dir[i][1];
if(judge(nx, ny) && g[t. f][nx][ny] != '*' && cnt[t. f][nx][ny] == inf){
if(g[t. f][nx][ny] == '#'){
cnt[t. f][nx][ny] = cnt[t. f][t. x][t. y] + 1;
if(cnt[! t. f][nx][ny] == inf){
cnt[! t. f][nx][ny] = cnt[t. f][t. x][t. y] + 1;
if(g[! t. f][nx][ny] != '#')
q. push({! t. f, nx, ny});
}
}
else{
cnt[t. f][nx][ny] = cnt[t. f][t. x][t. y] + 1;
q. push({t. f, nx, ny});
}
}
}
}
}

int main(){
int c;
cin >> c;
while(c --){
int T;
int ef, ex, ey;
cin >> n >> m >> T;
memset(cnt, 0x3f, sizeof(cnt));
for(int w = 0; w < 2; w ++)
for(int i = 0; i < n; i ++)
for(int j = 0; j < m; j ++){
cin >> g[w][i][j];
if(g[w][i][j] == 'P'){
ef = w, ex = i, ey = j;
}
}
for(int w = 0; w < 2; w ++)
for(int i = 0; i < n; i ++)
for(int j = 0; j < m; j ++){
if(g[w][i][j] == '#' && g[! w][i][j] == '*')
g[w][i][j] = '*';
if(g[w][i][j] == '#' && g[! w][i][j] == '#')
g[w][i][j] = g[! w][i][j] = '*';
}

bfs({0, 0, 0});
if(cnt[ef][ex][ey] <= T)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}

• 评论

• 下一篇
• 上一篇