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

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

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

    #include<bits/stdc++.h> using namespace std; int n,m,sum_p=0; struct node{ int x,y; }; char road[55][55]; int book[55][55]; int dir[][2]={{1,0},{-1,0},{0,-1},{0,1}}; void bfs(int sx,int sy){ queue<node> q; q.push({sx,sy}); book[sx][sy]=1; while(q.size()){ int tx=q.front().x,ty=q.front().y; q.pop(); for(int i=0;i<4;++i){ int nx=tx+dir[i][0],ny=ty+dir[i][1]; if(nx<1||nx>n||ny<1||ny>m||road[nx][ny]'#')continue; else if(road[nx][ny]'.'&&!book[nx][ny]){ q.push({nx,ny}); book[nx][ny]=book[tx][ty]+1; } } } // cout<<book[n][m]; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>m; for(int i=1;i<=n;++i) for(int j=1;j<=m;j){ cin>>road[i][j]; if(road[i][j]=='.')sum_p; } bfs(1,1); n==2?cout<<2:(book[n][m]?cout<<sum_p-book[n][m]:cout<<-1); cout<<"\n"; return 0; }

    userId_undefined
    未知
    模拟·模拟练习生倔强青铜冒泡宗师→排序元老
    4阅读
    0回复
    0点赞
暂无数据

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

首页