4 条题解
-
1
#include <bits/stdc++.h> #define LL long long using namespace std; const int N = 200 + 10; const int INF = 0x3f3f3f3f; int n , k , b ,x; int a [N]; bool v [N]; struct node { int t , step; }; queue < node > q; void bfs () { q.push( (node) {k , 0}); v [k] = 1; while (!q.empty()) { node top = q.front(); if ( top.t == b ) { cout << top.step; exit (0); } q.pop(); if ( !v [top.t - a [top.t]] && top.t - a [top.t] >= 1) { v [top.t - a [top.t]] = 1; q.push ( (node) { top.t - a [top.t] , top.step + 1 }); } if ( !v [top.t + a [top.t]] && top.t + a [top.t] <= n) { v [top.t + a [top.t]] = 1; q.push ( (node) { top.t + a [top.t] , top.step + 1 }); } } cout << -1; } int main() { cin >> n >> k >> x; for (int i = 1; i <= n; i++) cin >> a [i]; return 0; }
信息
- ID
- 3064
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 6
- 标签
- 递交数
- 181
- 已通过
- 61
- 上传者