提交测试点
#include <bits/stdc++.h>
using namespace std;
const int N=209;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
char maps[N][N];
int mon[N][N];
bool vis[N][N];
int check[N][N];
queue<pair<int,int>> q;
int main()
{
bool tp=false;
int n,m,sx,sy,ex,ey;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
string x;
cin>>x;
for(int j=0;j<m;j++)
{
maps[i][j+1]=x[j];
if(x[j]=='S')
{
sx=i;
sy=j+1;
}
if(x[j]=='T')
{
ex=i;
ey=j+1;
}
}
}
int w,enery=0;
cin>>w;
for(int i=1;i<=w;i++)
{
int x,y,e;
cin>>x>>y>>e;
mon[x][y]=e;
}
q.push({sx,sy});
vis[sx][sy]=true;
while(!q.empty())
{
int x=q.front().first;
int y=q.front().second;
if(mon[x][y])
{
enery=max(enery,mon[x][y]);
mon[x][y]=0;
}
else
{
enery=check[x][y];
}
if(x==ex&&y==ey)
{
cout<<"Yes";
tp=true;
break;
}
if(enery<=0)
{
vis[x][y]=false;
enery=check[x][y];
q.pop();
continue;
}
for(int i=0;i<4;i++)
{
int xx=x+dx[i];
int yy=y+dy[i];
if(!vis[xx][yy]&&maps[xx][yy]!='#'&&xx>0&&xx<=n&&yy>0&&yy<=m)
{
vis[xx][yy]=true;
q.push({xx,yy});
check[xx][yy]=enery-1;
}
}
q.pop();
}
if(!tp)
{
cout<<"No";
}
system("pause");
return 0;
}