5 条题解
-
2
AC简捷代码给个点赞吧qwq
#include<bits/stdc++.h> using namespace std; const int N = 2e2+5; int k [N],n,a,b,vis[N]; int bfs(int x) { queue<pair<int,int> >q; q.push({x,0}); vis[x]=1; while(!q.empty()) { pair<int,int> cur=q.front(); int u=cur.first,v=cur.second; q.pop(); if(u==b)return v; if(u-k[u]>=1&&!vis[u-k[u]]) { q.push({u-k[u],v+1}); vis[u-k[u]]=1; } if(u+k[u]<=n&&!vis[u+k[u]]) { q.push({u+k[u],v+1}); vis[u+k[u]]=1; } } return -1; } int main() { cin >> n >> a >> b; for(int i = 1;i <= n;i++)cin>>k[i]; cout<<bfs(a); return 0; }
信息
- ID
- 3064
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 6
- 标签
- 递交数
- 318
- 已通过
- 107
- 上传者