0分求调
查看原帖
0分求调
1800090
zhoujifeixingyuan楼主2025/8/4 11:21
#include <bits/stdc++.h>
using namespace std;

char s[110][110];
int past[10010][4];
int n,m;
int head=1,tail=1;
int dx[5]= {0,0,1,0,-1};
int dy[5]= {0,1,0,-1,0};
bool f=false;
int main()
{
        cin>>n>>m;
        for(int i=1; i<=n; i++)
        {
                for(int j=1; j<=m; j++)
                {
                        cin>>s[i][j];
                }
        }
        s[1][1]='#';
        past[head][1]=1;
        past[head][2]=1;
        past[head][3]=head;

        while(head<=tail)
        {
                for(int i=1; i<=4; i++)
                {
                        int tx=past[head][1]+dx[i];
                        int ty=past[head][2]+dy[i];
                        if(s[tx][ty]=='.')
                        {
                                tail++;
                                past[tail][1]=tx;
                                past[tail][2]=ty;
                                past[tail][3]=head;
                                s[tx][ty]='#';
                                if(tx==n&&ty==m)
                                {
                                        cout<<"yes"<<endl;
                                        f=!f;
                                        break;
                                }
                        }
                }
                head++;
        }
        if(f==false)
        {
                cout<<"no";
        }

        return 0;
}
/*
struct node
{
        int x;
        int y;
};

stack<node> printer;

void print(int last)
{
        while(past[last-1][3]>0)
        {
                node a;
                a.x=past[last][1];
                a.y=past[last][2];
                printer.push(a);
                last=past[last][3];
        }
        node a;
        a.x=past[last][1];
        a.y=past[last][2];
        printer.push(a);
        while (printer.empty()==false) {
		cout<<printer.top().x<<" "<<printer.top().y<<endl;
		printer.pop();
        }
}

*/

注释的那部分是输出路径的代码,可以配合那段代码去调,只要回复就关注,谢谢各位大佬

2025/8/4 11:21
加载中...