acgo题库
  • 首页
  • 题库
  • 学习
  • 天梯
  • 备赛

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
  • 竞赛
  • 讨论
  • 团队
  • 商城
登录
注册
题目详情提交记录(0)
  • 666

    #include<bits/stdc++.h> using namespace std; char a[105][105]; int sx,sy,zx,zy; int dx[5]={0,0,1,0,-1}; int dy[5]={0,1,0,-1,0}; int c; int n,m; struct node{ int x,y,step; }l,r; void bfs(int x, int y){ queue<node>q; q.push({x,y,0}); while(q.size()){ r=q.front(); q.pop(); if(r.xzx&&r.yzy){ cout<<r.step<<endl; return; } for(int i=1;i<=4;i++){ l.x=r.x+dx[i]; l.y=r.y+dy[i]; l.step=r.step+1; if(l.x>n||l.x<1||l.y>m||l.y<1)continue; if(a[l.x][l.y]'#')continue; q.push(l); a[l.x][l.y]='#'; } } cout<<-1<<endl; } int main(){ cin>>c; while(c--){ cin>>n>>m; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>a[i][j]; if(a[i][j]'S'){ sx=i; sy=j; a[sx][sy]='#'; }else if(a[i][j]=='E'){ zx=i; zy=j; } } } bfs(sx,sy); } }

    userId_undefined
    神
    I/O·IO入门者循环·循环打卡人模拟·模拟练习生分支·分支解题者造物者递归·套娃学徒
    1阅读
    0回复
    0点赞
暂无数据

提交答案之后,这里将显示提交结果~

首页