反其道而行之,广搜
2024-05-22 17:59:46
发布于:广东
AC代码
#include<bits/stdc++.h>
#include<queue>
using namespace std;
int n,****[50][50],vis[50][50],dir[4][2]={1,0,0,1,-1,0,0,-1},flag;
struct node{
int x,y;
};
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>mp[i][j];
}
}
queue<node> q;
q.push({1,1});
vis[1][1]=1;
while(!q.empty()){
node r=q.front();
q.pop();
if(r.x==n&&r.y==m){
flag=1;
break;
}
for(int i=0;i<4;i++){
node l;
l.x=r.x+dir[i][0];
l.y=r.y+dir[i][1];
if(l.x>=1&&l.x<=n&&l.y>=1&&l.y<=m&&!mp[l.x][l.y]&&!vis[l.x][l.y]){
vis[l.x][l.y]=1;
q.push(l);
}
}
}
if(flag)cout<<"YES\n";
else cout<<"NO\n";
return 0;
}
全部评论 1
/code/judger/run/20260713/5119032631297572961/main.cpp:4:11: error: expected unqualified-id before '[' token
4 | int n,[50][50],vis[50][50],dir[4][2]={1,0,0,1,-1,0,0,-1},flag;
| ^
/code/judger/run/20260713/5119032631297572961/main.cpp:4:61: error: expected unqualified-id before ',' token
4 | int n,[50][50],vis[50][50],dir[4][2]={1,0,0,1,-1,0,0,-1},flag;
| ^
/code/judger/run/20260713/5119032631297572961/main.cpp:4:66: error: expected constructor, destructor, or type conversion before ';' token
4 | int n,****[50][50],vis[50][50],dir[4][2]={1,0,0,1,-1,0,0,-1},flag;
| ^
compilation terminated due to -fmax-errors=3.2天前 来自 江苏
0









有帮助,赞一个