// UVa 11959 - Dice
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
class Die {
// Represents a regular 3D die.
private:
const static int number_of_corners = 8;
int faces[7];
vector<int> getCorner(int a, int b, int c) {
vector<int> corner;
corner.push_back(faces[a]);
corner.push_back(faces[b]);
corner.push_back(faces[c]);
if (corner[1] < corner[0] && corner[1] < corner[2]) {
int tmp = corner[0];
corner[0] = corner[1];
corner[1] = corner[2];
corner[2] = tmp;
} else if (corner[2] < corner[0] && corner[2] < corner[1]) {
int tmp = corner[0];
corner[0] = corner[2];
corner[2] = corner[1];
corner[1] = tmp;
}
return corner;
}
public:
Die(int front, int back, int left, int right, int bottom, int top) {
faces[1] = front;
faces[2] = back;
faces[3] = left;
faces[4] = right;
faces[5] = bottom;
faces[6] = top;
}
// gets all corners of the dice as three colors in clockwise order
vector<vector<int> > getCorners() {
vector<vector<int> > corners;
corners.push_back(getCorner(6, 1, 3));
corners.push_back(getCorner(6, 4, 1));
corners.push_back(getCorner(6, 2, 4));
corners.push_back(getCorner(6, 3, 2));
corners.push_back(getCorner(5, 1, 4));
corners.push_back(getCorner(5, 3, 1));
corners.push_back(getCorner(5, 2, 3));
corners.push_back(getCorner(5, 4, 2));
return corners;
}
// returns true if both dice are exactly the same, i.e. they look the same to a human observer
bool compare(Die anotherDie) {
vector<vector<int> > thisCorners = getCorners();
vector<vector<int> > otherCorners = anotherDie.getCorners();
bool matched[number_of_corners] = { 0 };
for (int i = 0; i < number_of_corners; i++) {
bool found = false;
for (int j = 0; j < number_of_corners && !found; j++)
if (!matched[j] && thisCorners[i][0] == otherCorners[j][0] && thisCorners[i][1] == otherCorners[j][1] && thisCorners[i][2] == otherCorners[j][2]) {
matched[j] = true;
found = true;
break;
}
if (!found)
return false;
}
return true;
}
};
Die buildDie(int s) {
int top = s / 100000;
int bot = s / 10000 % 10;
int fro = s / 1000 % 10;
int lft = s / 100 % 10;
int bck = s / 10 % 10;
int rgt = s % 10;
return Die(fro, bck, lft, rgt, bot, top);
}
int main() {
int cases;
cin >> cases;
for (int cas = 1; cas <= cases; cas++) {
int s[2];
cin >> s[0] >> s[1];
Die d1 = buildDie(s[0]);
Die d2 = buildDie(s[1]);
cout << (d1.compare(d2) ? "Equal" : "Not Equal") << endl;
}
return 0;
}
Friday, April 24, 2015
UVa 11959 - Dice
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment