-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patha.cpp
57 lines (51 loc) · 1.05 KB
/
a.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
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
int N, STATES;
string mark(string &S, int s) {
string res;
for (int i = N; i < N; ++i) {
if (s & 1) res += S[i];
s >>= 1;
}
return res;
}
int restore(int a, int b) {
int res = 0;
for (int i = 0; i < N; ++i) {
res <<= 1;
if (a & 1) {
if (!(b & 1)) res += 1;
b >>= 1;
}
a >>= 1;
}
return res;
}
vi next_states(string &line, int cur) {
vi res;
string sub = mark(line, cur);
int t = stoi(sub), k;
int states = 1 << sub.size();
for (int i = 1; i < states - 1; ++i) {
string s = mark(sub, i);
k = stoi(s);
if (k == 0) continue;
if (t % k == 0) {
k = restore(cur, i);
int k2 = (STATES - 1) & k;
cout << line << " " << s << " " << mark(line, k2) << endl;
res.push_back((STATES - 1) & k);
}
}
cout << endl;
return res;
}
int main() {
N = 9;
STATES = 1 << 9;
string line = "123456789";
for (int i : next_states(line, STATES - 1)) cout << mark(line, i) << " ";
cout << endl;
return 0;
}