全部评论 4

  • 中文感叹号?

    2024-08-12 来自 湖南

    0
  • 看看题目

    2024-08-12 来自 湖南

    0
  • 哦西八嘎

    2024-08-12 来自 广东

    0
  • #include <bits/stdc++.h>
    using namespace std;

    long long n, m, cnt;
    int dx[] = {-1, 1, 1};
    bool vis[10000005];

    struct node{
    int x;
    int step;
    };

    void bfs() {
    queue<node> q;
    vis[n] = 1;
    q.push({n, 0});
    while (!q.empty()) {
    node f = q.front();
    q.pop();
    if (f.x == m) {
    cout << f.step;
    return;
    }
    for (int i = 0; i < 3; i ++) {
    dx[2] = f.x;
    long long nx = f.x + dx[i];
    if (nx >= 0 && nx <= 1LL * 1000000 && !vis[nx]) {
    vis[nx] = 1;
    q.push({nx, f.step + 1});
    }
    }
    }
    cout << 0;
    }

    int main() {
    cin >> n >> m;
    bfs();

    return 0;
    

    }

    2024-07-31 来自 广东

    0

热门讨论