题目
样例
这道题,比赛的时候一直wa,事后看了题解也没找到问题,最后发现数组开小了。。。哭死,其实早点用队列存就好了,就不用管长度的问题了!
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <string.h>
#define INF 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
#define _for1(i,a,b) for( int i=(a); i<(b); ++i)
#define _for2(i,a,b) for( int i=(a); i>(b); i--)
#define _rep1(i,a,b) for( int i=(a); i<=(b); ++i)
#define _rep2(i,a,b) for( int i=(a); i>=(b); i--)
typedef long long ll;
using namespace std;
typedef long long ll;
const int N = 2;
const int MOD = 1000000009;
#define maxn 1005
struct poi {
int x, y, t;
poi() {}
poi(int x, int y, int t) :x(x), y(y), t(t) {}
};
int n, m;
char a[maxn][maxn];
poi Y[1000005];
int Yl;
int used[maxn][maxn];
int vis[maxn][maxn];
int dir[4][2] = { 0, 1, 1, 0, 0, -1, -1, 0 };
bool bfs() {
mem(used, 0);
mem(vis, 0);
queue<poi> q;
_for1(i, 0, Yl) {
q.push(Y[i]);
}
while (q.size()) {
poi u = q.front();
q.pop();
_for1(i, 0, 4) {
int x = u.x + dir[i][0],
y = u.y + dir[i][1],
t = u.t - 1;
if (t > 7 && x >= 0 && x < n && y >= 0 && y < m && a[x][y] == '0' && used[x][y] < t) {
q.push(poi(x, y, t));
used[x][y] = t;
}
}
}
_for1(i, 0, n) {
_for1(j, 0, m) {
if (used[i][j] <= 7 && a[i][j] == '0') {
return 0;
}
}
}
return 1;
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
mem(Y, 0);
Yl = 0;
scanf("%d%d", &n, &m);
_for1(i, 0, n)
scanf("%s", a + i);
_for1(i, 0, n) {
_for1(j, 0, m) {
if (a[i][j] == 'Y') {
Y[Yl].x = i;
Y[Yl].y = j;
Y[Yl].t = 15;
Yl++;
//q.push(poi(i, j, 15));
}
else if (a[i][j] == 'H') {
Y[Yl].x = i;
Y[Yl].y = j;
Y[Yl].t = 14;
Yl++;
}
else if (a[i][j] == 'F') {
Y[Yl].x = i;
Y[Yl].y = j;
Y[Yl].t = 12;
Yl++;
}
}
}
printf("%s", bfs() ? "No\n" : "Yes\n");
}
return 0;
}