WhaT_iS_My_naMe @ 2024-09-29 18:18:36
我搞了半天写出来的代码,发现先是把列的判断写成了n,接着是把输出的大小写写错了:
#include<bits/stdc++.h>
using namespace std;
int cnt[114][114];
int a[114][114];
int n, m;
int xf[]
{
0, 0, 1, -1
};
int yf[]
{
1, -1, 0, 0
};
struct h
{
int x, y;
h(int x, int y)
{
this->x = x;
this->y = y;
}
};
int bfs()
{
queue<h>q;
q.push(h(0,0));
while(q.size())
{
h now = q.front();
q.pop();
if(cnt[now.x][now.y])
{
continue;
}
if(now.x >= 0 && now.y >= 0 && now.x < n && now.y < n && a[now.x][now.y] == '.')
{
// cout<<now.x<<' '<<now.y<<endl;
cnt[now.x][now.y] = 1;
if(now.x == n - 1 && now.y == m - 1)
{
return 1;
}
for(int i = 0; i <= 3; ++i)
{
q.push(h(now.x + xf[i], now.y + yf[i]));
}
}
}
return 0;
}
int main()
{
cin >> n >> m;
for(int i = 0; i < n; ++i)
{
string tmp;
cin >> tmp;
for(int j = 0; j < m; ++j)
{
a[i][j] = tmp[j];
}
}
if(bfs())
{
cout<<"YES";
}
else
{
cout<<"NO";
}
}
by xiaozutupian @ 2024-11-11 17:19:25
写DFS时看到这个讨论,还在笑笨蛋lz的错误
然后调BFS调了二十分钟发现自己的m也写成n了,我是笨蛋