-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUVA-12160.cpp
More file actions
40 lines (34 loc) · 896 Bytes
/
UVA-12160.cpp
File metadata and controls
40 lines (34 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <bits/stdc++.h>
using namespace std;
int dist[10000];
int b[15];
int main() {
ios::sync_with_stdio(0);
int l, u, r;
int caso = 1;
while (cin >> l >> u >> r && (l || u || r)) {
for (int i = 0; i < r; ++i) {
cin >> b[i];
}
queue<int> q;
q.push(l);
int ans = 0;
memset(dist, -1, sizeof dist);
dist[l] = 0;
while (!q.empty()) {
int at = q.front();
q.pop();
for (int i = 0; i < r; ++i) {
int to = (at + b[i]) % 10000;
if (dist[to] == -1) {
dist[to] = dist[at] + 1;
q.push(to);
}
}
}
cout << "Case " << caso++ << ": ";
if (dist[u] == -1) cout << "Permanently Locked" << endl;
else cout << dist[u] << endl;
}
return 0;
}