Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- struct Cube {
- int upper_face, lower_face;
- vector<int> middle_faces;
- Cube() { middle_faces = vector<int>(4); }
- vector<int> get_cube() {
- vector<int> c = middle_faces;
- c.push_back(upper_face);
- c.push_back(lower_face);
- return c;
- }
- void rotate_vert() {
- int temp_upper = upper_face;
- int temp_lower = lower_face;
- upper_face = middle_faces[0];
- lower_face = middle_faces[2];
- middle_faces[0] = temp_lower;
- middle_faces[2] = temp_upper;
- }
- void rotate_horiz() {
- middle_faces = vector<int> { middle_faces[1], middle_faces[2], middle_faces[3], middle_faces[0] };
- }
- };
- vector<Cube> cubes;
- vector<int> father, sz;
- int ans;
- void gen(Cube a, int k, set<vector<int>> &possibilities) {
- if(k == 8) return;
- possibilities.insert(a.get_cube());
- Cube c = a, d = a;
- c.rotate_horiz();
- d.rotate_vert();
- gen(c, k + 1, possibilities);
- gen(d, k + 1, possibilities);
- }
- int find(int x) {
- if(x == father[x]) return x;
- return father[x] = find(father[x]);
- }
- void join(int x, int y) {
- x = find(x); y = find(y);
- if(x == y) return;
- if(sz[x] > sz[y]) swap(x, y);
- father[x] = y;
- sz[y] += sz[x];
- ans--;
- }
- int32_t main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- int n;
- while(cin >> n and n) {
- cubes = vector<Cube>(n);
- father = vector<int>(n);
- sz = vector<int>(n);
- ans = n;
- for(int i= 0; i < n; i++)
- father[i] = i, sz[i] = 1;
- map<vector<int>, int> existing_cube;
- for(int i = 0; i < n; i++) {
- cin >> cubes[i].upper_face;
- for(int j = 0; j < 4; j++)
- cin >> cubes[i].middle_faces[j];
- cin >> cubes[i].lower_face;
- set<vector<int>> possibilities;
- gen(cubes[i], 0, possibilities);
- for(auto c : possibilities) {
- if(existing_cube.count(c)) {
- int j = existing_cube[c];
- join(i, j);
- }
- }
- existing_cube[ cubes[i].get_cube() ] = i;
- }
- cout << ans << '\n';
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment