-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcicades.cpp
More file actions
30 lines (28 loc) · 824 Bytes
/
cicades.cpp
File metadata and controls
30 lines (28 loc) · 824 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
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
std::pair<bool, bool> isPossible(std::vector<int> pos) {
return std::make_pair<bool, bool>(std::abs(pos[0] - pos[1]) > 1, std::abs(pos[1] - pos[2]) > 1);
}
int main() {
unsigned int moves = 0;
std::vector<int> pos(3);
std::cin >> pos[0] >> pos[1] >> pos[2];
std::sort(pos.begin(), pos.end());
while(isPossible(pos).first || isPossible(pos).second) {
if(isPossible(pos).first && isPossible(pos).second)
if(std::abs(pos[0] - pos[1]) > std::abs(pos[1] - pos[2]))
pos[2] = (pos[0] + pos[1]) / 2;
else
pos[0] = (pos[1] + pos[2]) / 2;
else if(isPossible(pos).first)
pos[2] = (pos[0] + pos[1]) / 2;
else
pos[0] = (pos[1] + pos[2]) / 2;
std::sort(pos.begin(), pos.end());
moves++;
}
std::cout << moves;
return 0;
}