poj1046

package easy;


import java.util.Scanner;

/**
 *poj1046 easy
 * @author NC
 */
public class Poj1046 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        if (scan.hasNext()) {
            int[] r = new int[16];
            int[] g = new int[16];
            int[] b = new int[16];
            for (int i = 0; i < 16; i++) {
                r[i] = scan.nextInt();
                g[i] = scan.nextInt();
                b[i] = scan.nextInt();
            }

            while (scan.hasNext()) {
                int rr = scan.nextInt();
                int gg = scan.nextInt();
                int bb = scan.nextInt();
                if (rr == -1 && gg == -1 && bb == -1) {
                    break;
                }
                double[] d = new double[16];
                for (int i = 0; i < 16; i++) {
                    double sr = java.lang.Math.pow(rr - r[i], 2);
                    double sg = java.lang.Math.pow(gg - g[i], 2);
                    double sb = java.lang.Math.pow(bb - b[i], 2);
                    d[i] = java.lang.Math.sqrt(sr + sg + sb);
                }
                int min = 0;
                for (int i = 1; i < 16; i++) {
                    if (d[i] < d[min]) {
                        min = i;
                    }
                }
                System.out.println("(" + rr + "," + gg + "," + bb + ")"
                        + " maps to (" + r[min] + "," + g[min] + "," + b[min] + ")");
            }

        }
    }
}

你可能感兴趣的:(java)