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 1127. Colored Bricks

java AC solution
Posted by esbybb 5 Oct 2015 20:49
//package timus;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;

public class p1127 {
    static int z[] = new int[90];
    public static void main(String[] args) {
        int t = 0;
        for (int y:"ABCGORSVWY".getBytes()) {
            z[y] = t++;
        }
        InputStream is = System.in;
        Scanner sc = new Scanner(new InputStreamReader(is));
        int N = sc.nextInt();
        int max = 0;
        for (int i=0; i<N; i++) {
            byte[]yn = sc.next().getBytes();
            for (int j=0; j<24; j++) {
                int a = x[j][0];
                int b = x[j][1];
                int c = x[j][2];
                int d = x[j][3];
                a = yn[a-1];
                b = yn[b-1];
                c = yn[c-1];
                d = yn[d-1];
                a = z[a];
                b = z[b];
                c = z[c];
                d = z[d];
                int h = hash(a,b,c,d);
                u[h]++;
                max = Math.max(max, u[h]);
            }
        }
        System.out.println(max);
    }
    static int u[] = new int[10000];
    static int[][] x = new int[][]{
        {1,3,4,2, 5,6},{2,1,3,4, 5,6},{4,2,1,3, 5,6},{3,4,2,1, 5,6},
        {3,5,2,6, 1,4},{6,3,5,2, 1,4},{2,6,3,5, 1,4},{5,2,6,3, 1,4},
        {3,1,2,4, 6,5},{4,3,1,2, 6,5},{2,4,3,1, 6,5},{1,2,4,3, 6,5},
        {5,1,6,4, 3,2},{4,5,1,6, 3,2},{6,4,5,1, 3,2},{1,6,4,5, 3,2},
        {5,3,6,2, 4,1},{2,5,3,6, 4,1},{6,2,5,3, 4,1},{3,6,2,5, 4,1},
        {5,4,6,1, 2,3},{1,5,4,6, 2,3},{6,1,5,4, 2,3},{4,6,1,5, 2,3}
    };
    //
    //front, right, left, back,     up, down
    static Integer hash(int a, int b, int c, int d) {
        return 1000 * a + 100 * b + 10 * c + d;
    }
}