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

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

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

    #include <bits/stdc++.h> using namespace std; const int N = 2e5+5; int n,k; int a[N]; void bfs(int x) { queue<int> q; q.push(x); a[x] = 0; while (!q.empty() ) { int r = q.front() ; q.pop(); if(r == k) { cout<<a[k]; return ; }else { if(a[r-1] == 0 && r>=1){ a[r-1] = a[r]+1; q.push(r-1); }if(a[r+1] == 0 && (r+1)<=100000){ a[r+1] = a[r]+1; q.push(r+1); }if(a[2r] == 0 && (2r)<=100000){ a[r2] = a[r]+1; q.push(r2); } } } } int main() { cin>>n>>k; bfs(n); return 0; }

    userId_undefined

    Hachiware

    7月全勤卷王数组·数组操作员分支·分支解题者循环·循环打卡人格式·格式排版员字符串·魔法使
    1阅读
    0回复
    0点赞
  • =小吴

    #include <bits/stdc++.h> using namespace std; struct node{ int x,t; }; queue<node>que; int n,k; bool vis[100010]; int bfs(){ while (!que.empty()){ node a=que.front(); que.pop(); if (a.x==k) return a.t; if (a.x-1>=0 &&a.x-1<=100000 &&vis[a.x-1]==0){ que.push({a.x-1,a.t+1}); vis[a.x-1]=1; } if (a.x+1>=0 &&a.x+1<=100000 &&vis[a.x+1]==0){ que.push({a.x+1,a.t+1}); vis[a.x+1]=1; } if (a.x2>=0 &&a.x2<=100000 &&vis[a.x2]==0){ que.push({a.x2,a.t+1}); vis[a.x*2]=1; } } } int main(){ cin>>n>>k; que.push({n,0}); vis[n]=1; cout<<bfs(); return 0; }

    userId_undefined

    小吴鼠鼠

    出道萌新贪心·贪心尝试者模拟·模拟练习生倔强青铜
    1阅读
    0回复
    0点赞
  • 家人们 不会看我的

    userId_undefined

    李佳怡

    出道萌新模拟·模拟练习生倔强青铜
    0阅读
    0回复
    0点赞
  • 题解

    userId_undefined

    zsy

    题解仙人快乐小狗时空双修者BUG超度大师秩序白银
    0阅读
    0回复
    0点赞

共24条

  • 1
  • 2
20条/页
跳至页
暂无数据

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

首页