ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1015. Test the Difference!

java AC code snippet
Posted by esbybb 8 Nov 2015 21:16
there are 24 unique sequences of edges for the specific cube, i use 12 sequences and flip flop front with back for each of them
    static int R[][] = new int[][] {
        {1,2,3, 4,5, 6},
        {5,3,1, 4,2, 6},
        {2,1,5, 4,3, 6},
        {3,5,2, 4,1, 6},

        {6,4,3, 1,5, 2},
        {5,3,6, 1,4, 2},
        {4,6,5, 1,3, 2},
        {3,5,4, 1,6, 2},

        {1,2,6, 3,4, 5},
        {6,4,2, 3,1, 5},
        {2,1,4, 3,6, 5},
        {4,6,1, 3,2, 5}
    };
    static int front_back_rotate[][] = new int[][]{{0,1,2,3,4,5},{0,1,4,5,2,3}};
    //left right top  front bottom back
    //0       1     2    3     4      5
    static boolean eqv(int a[], int b[]) {
        for (int[] r: R) {
            for (int[] I: front_back_rotate) {
                int front_back[] = new int[6];
                for (int i=0; i<6; i++) {
                    front_back[r[I[i]]-1] = a[i];
                }
                if (Arrays.equals(front_back, b)) return true;
            }
        }
        return false;
    }
Re: java AC code snippet
Posted by springWaltz 8 Sep 2021 18:08
You don't need to try all rotation combinations. Just rotate left and rotate down, use recursion and all combinations will be generated easily.