본문 바로가기

온라인 코딩/수학(Math)

[백준] 2756번 다트

 

 

문제

소스코드

 

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<iostream>
#include<vector>
#include<utility>
#include<math.h>
#include<algorithm>
 
using Position = std::pair<doubledouble>;
 
int GetScore(std::vector<Position>& player) {
    int sum{ 0 };
    //3번 진행
    for (int i = 0; i < 3++i) {
        //두 점사이의 거리( 원점은 0,0이기 때문에 곱셈만 진행)
        double len = sqrt((player[i].first * player[i].first) +
            (player[i].second * player[i].second));
        if (len <= 3) {
            sum += 100;
        }
        else if (len <= 6) {
            sum += 80;
        }
        else if (len <= 9) {
            sum += 60;
        }
        else if (len <= 12) {
            sum += 40;
        }
        else if (len <= 15) {
            sum += 20;
        }
    }
    return sum;
}
 
int main() {
    int testCase{};
    std::cin >> testCase;
 
    //Test Case 까지
    for (int i = 0; i < testCase; ++i) {
        std::vector<Position> v;
        std::vector<Position> player1;
        std::vector<Position> player2;
        //2번씩 6번
        for (int j = 0; j < 6++j) {
            Position p;
            std::cin >> p.first >> p.second;
            v.emplace_back(p);
        }
 
 
        //0~3까지는 플레이어1
        std::copy(v.begin(), v.begin() + 3std::back_inserter(player1));
        //4~6까지는 플레이어2
        std::copy(v.begin() + 3, v.end(), std::back_inserter(player2));
 
        int player1Score = GetScore(player1);
        int player2Score = GetScore(player2);
 
        std::cout << "SCORE: " << player1Score << " to " << player2Score << ", ";
        if (player1Score == player2Score) {
            std::cout << "TIE.\n";
        }
        else if (player1Score > player2Score) {
            std::cout << "PLAYER 1 WINS.\n";
        }
        else {
            std::cout << "PLAYER 2 WINS.\n";
        }
 
    } //end TestCase For
 
}
 

 

후기

이 문제는 해당하는 다트가 원의 어느 지점에 있는지 확인 후 3개의 합계를 계산해 누가 이겼는지 판정해주는 문제이다.

 

다트(x, y)와 원의 중점(0,0)에 두 점 사이의 거리를 계산 후 원의 반지름보다 작은 곳에 있으면 해당 점수를 얻는 방식으로 문제를 풀었다.

 

출처 및 레퍼런스

문제 링크: https://www.acmicpc.net/problem/2756