-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcola.cpp
69 lines (55 loc) · 1.12 KB
/
cola.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
61
62
63
64
65
66
67
68
69
#include <bitset>
#include <iostream>
#include <string>
/*
0
01
0110
01101001
01101001
0110
01
0
*/
using namespace std;
bool sprawdzRozdzial(string s, string &wynik) {
for (int i = 0; i < s.size(); i += 2) {
if (i < s.size() - 1) {
if (s[i] == '0' && s[i + 1] == '1') {
wynik += "0";
} else if (s[i] == '1' && s[i + 1] == '0') {
wynik += "1";
} else {
// nie da sie
return false;
}
} else { // ostatni element
wynik += s[i];
}
}
return true;
}
bool czyWCiagu(string s) {
string wynik;
if (s.size() <= 3)
return !(s == "111" || s == "000");
if (sprawdzRozdzial(s, wynik))
return czyWCiagu(wynik);
// Probujemy offset +1
wynik = (s[0] == '1') ? "0" : "1";
s.erase(0, 1);
if (sprawdzRozdzial(s, wynik))
return czyWCiagu(wynik);
return false;
}
int main() {
int ile = 0;
const int potega = 14;
const int warPotega = 1 << potega;
for (int i = 0; i < warPotega; i++) {
string s = bitset<(size_t)potega>(i).to_string();
if (czyWCiagu(s))
ile++;
}
cout << ile << " " << (float)ile / (float)warPotega;
}