[ABC348D] Medicines on Grid 求改!!!
代码如下:
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct point{
int x,y,step;
};
point q[10000005],s;
int front,rear;
int n,m,k;
int d[205][205];
string g[205];
int dx[10] = {-1,0,1,0};
int dy[10] = {0,1,0,-1};
signed main(){
cin>>n>>m;
for(int i = 1;i <= n;i++){
cin>>g[i];
g[i] = " "+g[i];
for(int j = 1;j <= m;j++){
if(g[i][j] == 'S'){
s.x = i;
s.y = j;
}
}
}
cin>>k;
for(int i = 1;i <= k;i++){
int a,b,c;
cin>>a>>b>>c;
d[a][b] = c;
}
front = 1,rear = 0;
q[++rear] = s;
while(front <= rear){
point u = q[front++];
point v;
if(d[u.x][u.y] > u.step){
v.step = d[u.x][u.y];
}
if(v.step == 0) continue;
for(int i = 0;i < 4;i++){
v.x = u.x+dx[i];
v.y = u.y+dy[i];
if(v.x < 1 || v.x > n || v.y < 1 || v.y > m) continue;
if(g[v.x][v.y] == '#') continue;
q[++rear] = v;
if(g[v.x][v.y] == 'T'){
cout<<"Yes"<<endl;
return 0;
}
}
}
cout<<"No"<<endl;
return 0;
}