Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- using namespace std;
- vector < short > clockk;
- bool check(vector < short > c)
- {
- for (int i = 0; i < 9; i++) {
- if (c[i] != 0)return false;
- }
- return true;
- }
- pair < vector < short >, vector < short > > change(pair < vector < short >, vector < short > > temp, int num)
- {
- if (num == 0) {
- temp.first[0] += 3;
- temp.first[1] += 3;
- temp.first[3] += 3;
- temp.first[4] += 3;
- temp.first[0] %= 12;
- temp.first[1] %= 12;
- temp.first[2] %= 12;
- temp.first[4] %= 12;
- return temp;
- }
- if (num == 1) {
- temp.first[0] += 3;
- temp.first[1] += 3;
- temp.first[2] += 3;
- temp.first[0] %= 12;
- temp.first[1] %= 12;
- temp.first[2] %= 12;
- return temp;
- }
- if (num == 2) {
- temp.first[1] += 3;
- temp.first[2] += 3;
- temp.first[4] += 3;
- temp.first[5] += 3;
- temp.first[1] %= 12;
- temp.first[2] %= 12;
- temp.first[4] %= 12;
- temp.first[5] %= 12;
- return temp;
- }
- if (num == 3) {
- temp.first[0] += 3;
- temp.first[3] += 3;
- temp.first[6] += 3;
- temp.first[0] %= 12;
- temp.first[3] %= 12;
- temp.first[6] %= 12;
- return temp;
- }
- if (num == 4) {
- temp.first[1] += 3;
- temp.first[3] += 3;
- temp.first[4] += 3;
- temp.first[5] += 3;
- temp.first[7] += 3;
- temp.first[1] %= 12;
- temp.first[3] %= 12;
- temp.first[4] %= 12;
- temp.first[5] %= 12;
- temp.first[7] %= 12;
- return temp;
- }
- if (num == 5) {
- temp.first[2] += 3;
- temp.first[5] += 3;
- temp.first[8] += 3;
- temp.first[2] %= 12;
- temp.first[5] %= 12;
- temp.first[8] %= 12;
- return temp;
- }
- if (num == 6) {
- temp.first[3] += 3;
- temp.first[4] += 3;
- temp.first[6] += 3;
- temp.first[7] += 3;
- temp.first[3] %= 12;
- temp.first[4] %= 12;
- temp.first[6] %= 12;
- temp.first[7] %= 12;
- return temp;
- }
- if (num == 7) {
- temp.first[6] += 3;
- temp.first[7] += 3;
- temp.first[8] += 3;
- temp.first[6] %= 12;
- temp.first[7] %= 12;
- temp.first[8] %= 12;
- return temp;
- }
- if (num == 8) {
- temp.first[4] += 3;
- temp.first[5] += 3;
- temp.first[7] += 3;
- temp.first[8] += 3;
- temp.first[4] %= 12;
- temp.first[5] %= 12;
- temp.first[7] %= 12;
- temp.first[8] %= 12;
- return temp;
- }
- }
- void BFS()
- {
- queue < pair < vector < short >, vector < short > > > q;
- vector < short > temp;
- for (int i = 0; i < 9; i++)
- temp.push_back(0);
- q.push({clockk, temp});
- while (!q.empty()) {
- pair < vector < short >, vector < short > > u = q.front();
- q.pop();
- if (check(u.first)) {
- for (int i = 0; i < 9; i++) {
- while (u.second[i]--) {
- cout << i + 1 << ' ';
- }
- }
- return;
- }
- if (q.size() < 10000) {
- for (int i = 0; i < 9; i++) {
- if (u.second[i] < 3) {
- pair < vector < short >, vector < short > > v = u;
- u.second[i]++;
- u = change(u, i);
- q.push(u);
- u = v;
- }
- }
- }
- }
- }
- int main()
- {
- short num;
- for (int i = 0; i < 9; i++) {
- cin >> num;
- num %= 12;
- clockk.push_back(num);
- }
- BFS();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement