-
Notifications
You must be signed in to change notification settings - Fork 0
/
1dfroggereasy.cpp
47 lines (43 loc) · 1.03 KB
/
1dfroggereasy.cpp
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
41
42
43
44
45
46
47
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s, m, tmp, curr, counter = 0;
cin >> n >> s >> m;
int a = n;
vector<int> nums;
vector<bool> visited;
while(a--) {
cin >> tmp;
nums.push_back(tmp);
visited.push_back(false);
}
curr = s - 1;
while(true) {
// cout << curr << " " << n << endl;
if(nums[curr] == m) {
cout << "magic" << endl;
cout << counter;
break;
}
else if(curr < 0) {
cout << "left" << endl;
cout << counter;
break;
}
else if(curr >= n) {
cout << "right" << endl;
cout << counter;
break;
}
if(visited[curr]) { //square already visited, loop
cout << "cycle" << endl;
cout << counter;
break;
}
else { //square not visited
visited[curr] = true;
curr += nums[curr];
}
counter++;
}
}