'commit'
This commit is contained in:
33
TangDou/LanQiaoBei/LanQiaoBei13GuoSai/3_2.cpp
Normal file
33
TangDou/LanQiaoBei/LanQiaoBei13GuoSai/3_2.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
typedef pair<int, int> PII;
|
||||
const int N = 110;
|
||||
int a[N];
|
||||
int st[N];
|
||||
int n;
|
||||
void bfs() {
|
||||
queue<PII> q; // first:当前木桩号 sencond:从起点走了几步到达了当前的木桩
|
||||
q.push({1, 0});
|
||||
st[1] = 1;
|
||||
while (q.size()) {
|
||||
auto t = q.front();
|
||||
q.pop();
|
||||
if (t.first == n) {
|
||||
cout << t.second << endl;
|
||||
exit(0);
|
||||
}
|
||||
for (int i = 1; i <= a[t.first]; i++) {
|
||||
int x = t.first + i;
|
||||
if (st[x]) continue;
|
||||
q.push({x, t.second + 1});
|
||||
st[x] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) cin >> a[i];
|
||||
bfs();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user