A brute-force problem.
Given two six-sided dice in a certain orientation, you have to determine whether they’re equal. The die is represented by an integer with each digit representing one face of the die as follows: top, bottom, front, left, back, right
To check whether d1 and d2 are equivalent, keep d1 in a fixed orientation and rotate d2 to all possible orientation. If they match in any orientation, they’re equal.
Now, we need to know how to get all possible orientations; If we rotate the die so that each face appears on top once, that’s 6 orientations. For each of these, we can spin the die along the y-axis to get 4 more positions. Summing up, that’s a total of 6x4
different orientations we have to check.
Time to actually implement those permutations. Here are two macros that we’ll rely on in generating the orientations. R(d)
: rotates the die d
clockwise along the y-axis, F(d)
: rotates along the x-axis:
#define R(d) ( ((d) & 0x000F00) << 12 | ((d) & 0x00000F) << 16 | ((d) & 0x00F0F0) | ((d) & 0x0F0000) >> 8 | ((d) & 0xF00000) >> 20 ) #define F(d) ( ((d) & 0x0000F0) << 16 | ((d) & 0x00F000) << 4 | ((d) & 0xF00000) >> 8 | ((d) & 0x000F0F) | ((d) & 0x0F0000) >> 12 )
The rest should be easier. Coded in C++:
#include <cstdio> using namespace std; #define R(d) ( ((d) & 0x000F00) << 12 | ((d) & 0x00000F) << 16 | ((d) & 0x00F0F0) | ((d) & 0x0F0000) >> 8 | ((d) & 0xF00000) >> 20 ) #define F(d) ( ((d) & 0x0000F0) << 16 | ((d) & 0x00F000) << 4 | ((d) & 0xF00000) >> 8 | ((d) & 0x000F0F) | ((d) & 0x0F0000) >> 12 ) bool E(long long d1, long long d2) { return ((d1) == (d2) || (d1) == R((d2)) || (d1) == R(R((d2))) || (d1) == R(R(R((d2))))); } char ans[2][16] = { "Not Equal", "Equal" }; int main() { long long t, d1, d2; scanf("%lld", &t); while (t--) { bool out = false; scanf("%llx %llx", &d1, &d2); out = E(d1, d2) || E(d1, F(d2)) || E(d1, F(F(d2))) || E(d1, F(F(F(d2)))) || E(d1, F(R(d2))) || E(d1, F(R(R(R(d2))))); printf("%s\n", ans[out]); } return 0; }
Rank 41.