codeground 연습문제 4 - 다트 게임

 이번 문제는 수학적인 계산을 필요로하는 문제이다.

"너는 수학적인 계산을 이용하여 게임을 만들 수 있니?" 라는 질문을 한다.

어렵지는 않지만 약간의 생각이 필요한 문제이다.



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.util.Scanner;
import static java.lang.Math.PI;

class Solution {
    static int Answer, T, N, A, B, C, D, E, x, y, quadrant, score = 0, tmp;
    static double distance, inclination;
    static int[] scoreData = {6, 13, 4, 18, 1, 20, 5, 12, 9, 14,
    11, 8, 16, 7, 19, 3, 17, 2, 15, 10};
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        T = sc.nextInt();
        for (int i = 0; i < T; i++) {
            A = sc.nextInt();B = sc.nextInt();
            C = sc.nextInt();D = sc.nextInt();
            E = sc.nextInt();N = sc.nextInt();
            Answer = 0;score = 0;
            for (int j = 0; j < N; j++) {
                x = sc.nextInt();y = sc.nextInt();
                distance = Math.sqrt(x*x + y*y);
                inclination = Math.atan2(y, x) * 180 / PI;
                tmp = ((int)(inclination + 369) / 18) % 20;

                if (distance < A) {
                    Answer += 50;
                }else if (distance > B && distance < C) {
                    Answer += scoreData[tmp] * 3;
                }else if (distance > D && distance < E) {
                    Answer += scoreData[tmp] * 2;
                }else if (distance > E) {

                }else {
                    Answer += scoreData[tmp];
                }
            }
            System.out.println("Case #"+(i+1));
            System.out.println(Answer);
        }
    }
}

이 블로그의 인기 게시물

웹툰 무료로 볼 수 있는 사이트

BackJoon 1011, Fly me to the alpha centauri, 규칙 찾기 문제

BaekJoon 6591, 이항 쇼다운 조합문제