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

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
登录
注册
题目详情题解(0)讨论(0)提交记录(0)
  • 我是林涵

    首先我是林涵本人,龟龟是我同桌,其次这题太水了: #include<bits/stdc++.h> using namespace std; struct node { int x,step; }; int vis[100005]; queue<node> que; int n,w; void bfs() { while(!que.empty()) { node t=que.front(); que.pop(); if(t.x==n) { cout<<t.step; return; } int nx=t.x+1; if(nx<=100000&&!vis[nx]) { vis[nx]=1; que.push((node){nx,t.step+1}); } nx=t.x-1; if(nx>=0&&!vis[nx]) { vis[nx]=1; que.push((node){nx,t.step+1}); } nx=t.x*2; if(nx<=100000&&!vis[nx]) { vis[nx]=1; que.push((node){nx,t.step+1}); } } } int main() { cin>>w>>n; vis[w]=1; que.push((node){w,0}); bfs(); }

    userId_undefined

    K

    倔强青铜
    10阅读
    3回复
    0点赞
首页