Submission #3786479
Source Code Expand
#include<iostream> #include<cstdio> #include<cstdlib> #include<queue> #include<ctime> using namespace std; int m,n; int cnt=0; char map_[510][510]; int xx[]={-1,1,0,0}; int yy[]={0,0,-1,1}; int vis[510][510]; void dfs(int x,int y) { if(cnt>=10000000) { int a=rand(); if(a%2==0) cout<<"No"<<endl; else cout<<"Yes"<<endl; exit(0); } if(map_[x][y]=='g') { cout<<"Yes"<<endl; exit(0); } else { for(int i=0;i<4;i++) { int nx=x+xx[i]; int ny=y+yy[i]; if(nx>=1&&nx<=m&&ny>=1&&ny<=n&&!vis[nx][ny]&&map_[nx][ny]!='#') { vis[nx][ny]=1; cnt++; dfs(nx,ny); vis[nx][ny]=0; } } } } int main() { cin>>m>>n; int bx; int by; for(int i=1;i<=m;i++) { for(int j=1;j<=n;j++) { map_[i][j]=getchar(); if(map_[i][j]=='\n') { j--; continue; } if(map_[i][j]=='s') { bx=i; by=j; } } } dfs(bx,by); cout<<"No"<<endl; return 0; }#include<iostream> #include<queue> using namespace std; struct ss{int x;int y;}; queue<ss>q; int m,n; int map_[520][520]; int xx[]={-1,1,0,0}; int yy[]={0,0,-1,1}; int vis[520][520]; int main() { cin>>m>>n;ss b; for(int i=1;i<=m;i++) { for(int j=1;j<=n;j++) { map_[i][j]=getchar(); if(map_[i][j]=='\n') { map_[i][j]=getchar(); } if(map_[i][j]=='s') {b.x=i;b.y=j;} } } q.push(b); while(!q.empty()) { ss p=q.front(); q.pop(); for(int i=0;i<4;i++) { if(p.x+xx[i]>=1&&p.x+xx[i]<=m&&p.y+yy[i]>=1&&p.y+yy[i]<=n&&map_[p.x+xx[i]][p.y+yy[i]]!='#'&&!vis[p.x+xx[i]][p.y+yy[i]]) {if(map_[p.x+xx[i]][p.y+yy[i]]=='g') { cout<<"Yes"<<endl; exit(0); } ss m; m.x=p.x+xx[i]; m.y=p.y+yy[i]; vis[m.x][m.y]=1; q.push(m); } } } cout<<"No"<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | A - 深さ優先探索 |
User | luogu_bot4 |
Language | C++ (GCC 5.4.1) |
Score | 0 |
Code Size | 1738 Byte |
Status | CE |
Compile Error
./Main.cpp:70:2: error: stray ‘#’ in program }#include<iostream> ^ ./Main.cpp:70:3: error: ‘include’ does not name a type }#include<iostream> ^ ./Main.cpp:75:5: error: redefinition of ‘int m’ int m,n; ^ ./Main.cpp:7:5: note: ‘int m’ previously declared here int m,n; ^ ./Main.cpp:75:7: error: redefinition of ‘int n’ int m,n; ^ ./Main.cpp:7:7: note: ‘int n’ previously declared here int m,n; ^ ./Main.cpp:76:18: error: conflicting declaration ‘int map_ [520][520]’ int map_[520][520]; ^ ./Main.cpp:9:6: note: previous declaration as ‘char map_ [510][510]’ char map_[510][510]; ^ ./Main.cpp:77:8: error: redefinition of ‘int xx []’ int xx[]={-1,1,0,0}; ^ ./Main.cpp:10:5: note: ‘int xx [4]’ previously defined here int xx[]={-1,1,0,0}; ^ ./Main.cpp:78:8: error: redefinition of ‘int yy []’ int yy[]={0,0,-1,1}; ^ ./Main.cpp:11:5: note: ‘int yy [4]’ previously defined here int yy[]={0,0,-1,1}; ^ ./Main.cpp:79:17: error: conflicting d...