Relisc @ 2024-07-01 16:56:26
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
queue <PII> q;
const int N=1050;
char a[N][N];
bool st[N][N];
int n,m;
void bfs(int u,int v){
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
st[u][v]=true;
q.push({u,v});
while(!q.empty())
{
auto t=q.front();
q.pop();
for(int i=0;i<4;i++)
{
int x=t.first+dx[i],y=t.second+dy[i];
if(1<=x && x<=n && 1<=y && y<=m && !st[x][y] && a[x][y]=='.')
q.push({x,y});
}
}
if(!st[n][m]) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>a[i][j];
bfs(1,1);
return 0;
}
by do_it_tomorrow @ 2024-07-01 17:00:41
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
queue <PII> q;
const int N=1050;
char a[N][N];
bool st[N][N];
int n,m;
void bfs(int u,int v){
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
st[u][v]=true;
q.push({u,v});
while(!q.empty())
{
auto t=q.front();
q.pop();
for(int i=0;i<4;i++)
{
int x=t.first+dx[i],y=t.second+dy[i];
if(1<=x && x<=n && 1<=y && y<=m && !st[x][y] && a[x][y]=='.')
q.push({x,y}) ,st[x][y]=true; //here
}
}
if(!st[n][m]) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>a[i][j];
bfs(1,1);
return 0;
}
by do_it_tomorrow @ 2024-07-01 17:00:51
@Relisc
by Relisc @ 2024-07-01 17:06:10
@do_it_tomorrow 奥!忘记改状态了,谢谢~