7 solutions

  • 0
    @ 2023-4-7 19:51:19

    稀里糊涂就过了,哈哈哈,祝大家好运,对了,那个起点要特判一下哦,注意了


    #include<iostream>
    using namespace std;
    const int N=1e2+10;
    int n;
    int sx,sy,ex,ey;
    int map[N][N];
    int vis[N][N]={0};
    int dx[4]={-1,0,1,0};
    int dy[4]={0,-1,0,1};
    void dfs(int x,int y)
    {
    	if(x>=n&&y>=n) return;
    	if(x==ex&&y==ey)
    	{
    		cout<<"YES";
    		return;
    	}
    	if(vis[x][y]==1) return;
    	vis[x][y]=1;
    	for(int i=0;i<4;i++)
    	{
    		int xx=dx[i]+x;
    		int yy=dy[i]+y;
    		if(vis[xx][yy]!=1&&xx>0&&xx<=n&&yy>0&&yy<=n)
    		{
    			vis[xx][yy]=1;
    			dfs(xx,yy);
    			vis[xx][yy]=0;
    		}
    	}
    	cout<<"NO";
    }
    int main()
    {
    	//cout<<N;
    	cin>>n;
    	for(int i=0;i<n;i++)
    	{
    		for(int j=0;j<n;j++)
    		{
    			cin>>map[i][j];
    		}
    	}
    	cin>>sx>>sy>>ex>>ey;
    	map[sx][sy]=1;
    	dfs(sx,sy);
    	return 0;
    }
    

    Information

    ID
    767
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    8
    Tags
    # Submissions
    927
    Accepted
    165
    Uploaded By