Trang

Chủ Nhật, 2 tháng 1, 2011

2101. Bullseye

import java.io.*;

public class Main {

    /**
     * http://acm.tju.edu.cn/toj/showp2101.html
     * @author hunglee
     */
    public static void main(String[] args) throws IOException {
        
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(
                new InputStreamReader(System.in)));
        
        double[] x = new double[6];
        double[] y = new double[6];
        double[] r = new double[6];
        int[] res = new int[2];
        
        while (in.nextToken() != StreamTokenizer.TT_EOF) {
            x[0] = in.nval;
            if (x[0] == -100)
                break;
            in.nextToken();
            y[0] = in.nval;
            for (int i = 1; i < 6; ++i) {
                in.nextToken();
                x[i] = in.nval;
                in.nextToken();
                y[i] = in.nval;
            }
            res[0] = res[1] = 0;
            for (int i = 0; i < 6; ++i)
                r[i] = Math.sqrt(x[i] * x[i] + y[i] * y[i]);
            for (int i = 0; i < 6; ++i)
                if (r[i] <= 3.0 || Math.abs(r[i] - 3.0) <= 0.000000001)
                    res[i/3] += 100;
                else if (r[i] <= 6.0 || Math.abs(r[i] - 6.0) <= 0.000000001)
                    res[i/3] += 80;
                else if (r[i] <= 9.0 || Math.abs(r[i] - 9.0) <= 0.000000001)
                    res[i/3] += 60;
                else if (r[i] <= 12.0 || Math.abs(r[i] - 12.0) <= 0.000000001)
                    res[i/3] += 40;
                else if (r[i] <= 15.0 || Math.abs(r[i] - 15.0) <= 0.000000001)
                    res[i/3] += 20;
            System.out.print("SCORE: " + res[0] + " to " + res[1]);
            if (res[0] == res[1])
                System.out.println(", TIE.");
            else if (res[0] > res[1])
                System.out.println(", PLAYER 1 WINS.");
            else
                System.out.println(", PLAYER 2 WINS.");
        }
    }

}

Không có nhận xét nào:

Đăng nhận xét