acgo题库
  • 首页
  • 题库
  • 题单
  • 竞赛
  • 讨论
  • 排行
  • 团队
  • 备赛专区

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
登录
注册
题目详情题解(0)讨论(0)提交记录(0)
  • 正经题解|仙岛求药

    【算法分析】 求最少需要多少步,考虑使用广搜。从起点开始进行搜索,当搜索到终点时就结束。 【参考代码】 【时间复杂度】 O(n∗m)O(n*m)O(n∗m) 【预计得分】 100pts100pts100pts

    userId_undefined

    AC君

    管理员
    倔强青铜
    176阅读
    0回复
    2点赞
  • 题解2

    userId_undefined

    人

    倔强青铜
    41阅读
    0回复
    2点赞
  • 正经的仙岛求药题解②

    题解 这不就是模板题吗!

    userId_undefined

    qianqian

    倔强青铜
    19阅读
    0回复
    1点赞
  • 广搜题解

    userId_undefined

    suyuhao_

    倔强青铜
    12阅读
    1回复
    1点赞
  • Tian Tian是我儿子

    #include <bits/stdc++.h> using namespace std; char MAP[2009][2009]; bool vis[2009][2009]; int dir[4][2] = { -1,0,0,1,1,0,0,-1 }; struct node { int x, y, step; }l,r; int main() { int n, m; cin >> n >> m; int sx, sy, ex, ey; for (int i = 1; i <= n; i++) { cin >> MAP[i] + 1; for (int j = 1; j <= m; j++) { if (MAP[i][j] == '@') { sx = i, sy = j; } else if (MAP[i][j] == '*') { ex = i, ey = j; } } } queue<node> q; q.push({ sx,sy,0 }); vis[sx][sy] = 1; while (q.size()) { r = q.front(); q.pop(); if (r.x == ex && r.y == ey) { cout << r.step; return 0; } for (int i = 0; i < 4; i++) { l.x = r.x + dir[i][0]; l.y = r.y + dir[i][1]; l.step = r.step + 1; if (l.x >= 1 && l.x <= n && l.y >= 1 && l.y <= m && !vis[l.x][l.y] && MAP[l.x][l.y] != '#') { vis[l.x][l.y] = 1; q.push(l); } } } cout << -1; return 0; }

    userId_undefined

    胡天维

    倔强青铜
    18阅读
    1回复
    0点赞
  • A8046

    userId_undefined

    CEGO.tyx

    荣耀黄金
    0阅读
    0回复
    0点赞
首页