警示后人
查看原帖
警示后人
1382196
WhaT_iS_My_naMe楼主2024/9/29 18:18

我搞了半天写出来的代码,发现先是把列的判断写成了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";
    }
}

不要和楼主一样犯同样~~~~低级~~~~的错误
2024/9/29 18:18
加载中...