-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathBunnyPuzzle.cpp
60 lines (58 loc) · 1.61 KB
/
BunnyPuzzle.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
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<iostream>
#include<cstdio>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<list>
#include<deque>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
#include<sstream>
#include<cstring>
using namespace std;
class BunnyPuzzle {
public:
int theCount(vector <int> bs) {
if (bs.size() == 2)
return 2;
int result = 0;
for (int i = 0; i < bs.size(); ++i) {
if (i > 1 && i < bs.size()-2) {
if (2*bs[i+1]-bs[i] > bs[i+2])
++result;
if (2*bs[i-1]-bs[i] < bs[i-2])
++result;
} else {
if (i == 0) {
if (2*bs[i+1]-bs[i] > bs[i+2]) {
++result;
}
}
if (i == 1 && i != bs.size()-2) {
++result;
if (2*bs[i+1]-bs[i] > bs[i+2]) {
++result;
}
}
if (i == bs.size()-1) {
if (2*bs[i-1]-bs[i] < bs[i-2]) {
++result;
}
}
if (i == bs.size()-2) {
++result;
if (2*bs[i-1]-bs[i] < bs[i-2]) {
++result;
}
}
}
}
return result;
}
};