7 solutions

  • 0
    @ 2022-12-31 15:41:59

    #include<bits/stdc++.h> using namespace std; /* 将字符串的空格变成“%20” int main() { string a; getline(cin,a); for(int i=0;i<a.size();++i) { if(a[i]' ') a.replace(i,1,"%20"); } cout<<a; } */ bool fd=false; const int N=1e3+10; int dirx[]={0,0,-1,1}; int diry[]={-1,1,0,0}; int maze[N][N]; int vis[N][N]; int n; int sx,sy,ex,ey; bool check(int x,int y) { if(x<=n&&x>=1&&y<=n&&y>=1&&!vis[x][y]&&maze[x][y]0) return true; return false; } void dfs(int x,int y) { if(vis[x][y]) //访问过了。返回 return ; vis[x][y]=true; if(xn&&yn) { fd=true; return ; } for(int i=0;i<4;i++) { int tx=x+dirx[i]; int ty=y+diry[i]; if(check(tx,ty)) dfs(tx,ty); } return ; } int main(){ cin>>n; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>maze[i][j]; cin>>sx>>sy>>ex>>ey; dfs(sx,sy); if(maze[sx][sy]==1||maze[ex][ey]==1) fd=false; puts(fd? "YES":"NO"); return 0; }

    Information

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