작성일 :

문제 링크

2756번 - 다트

설명

각 다트의 좌표를 점수로 변환해 두 플레이어의 합계를 비교하는 문제입니다.


접근법

중심에서의 거리 제곱을 구해 반지름 구간에 따라 점수를 부여합니다.

각 플레이어의 세 발씩 점수를 합산하고, 결과에 따라 승자 또는 무승부 형식으로 출력합니다.


Code

C#

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
using System;

class Program {
  static int Score(double x, double y) {
    var d2 = x * x + y * y;
    if (d2 <= 9) return 100;
    if (d2 <= 36) return 80;
    if (d2 <= 81) return 60;
    if (d2 <= 144) return 40;
    if (d2 <= 225) return 20;
    return 0;
  }

  static void Main() {
    var data = Console.In.ReadToEnd();
    var parts = data.Split();
    var idx = 0;
    var t = int.Parse(parts[idx++]);

    for (var tc = 0; tc < t; tc++) {
      var s1 = 0;
      var s2 = 0;
      for (var i = 0; i < 3; i++) {
        var x = double.Parse(parts[idx++]);
        var y = double.Parse(parts[idx++]);
        s1 += Score(x, y);
      }
      for (var i = 0; i < 3; i++) {
        var x = double.Parse(parts[idx++]);
        var y = double.Parse(parts[idx++]);
        s2 += Score(x, y);
      }

      if (s1 == s2) Console.WriteLine($"SCORE: {s1} to {s2}, TIE.");
      else if (s1 > s2) Console.WriteLine($"SCORE: {s1} to {s2}, PLAYER 1 WINS.");
      else Console.WriteLine($"SCORE: {s1} to {s2}, PLAYER 2 WINS.");
    }
  }
}

C++

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
#include <bits/stdc++.h>
using namespace std;

int score(double x, double y) {
  double d2 = x * x + y * y;
  if (d2 <= 9) return 100;
  if (d2 <= 36) return 80;
  if (d2 <= 81) return 60;
  if (d2 <= 144) return 40;
  if (d2 <= 225) return 20;
  return 0;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int t; cin >> t;
  for (int tc = 0; tc < t; tc++) {
    int s1 = 0, s2 = 0;
    for (int i = 0; i < 3; i++) {
      double x, y; cin >> x >> y;
      s1 += score(x, y);
    }
    for (int i = 0; i < 3; i++) {
      double x, y; cin >> x >> y;
      s2 += score(x, y);
    }

    if (s1 == s2) cout << "SCORE: " << s1 << " to " << s2 << ", TIE.\n";
    else if (s1 > s2) cout << "SCORE: " << s1 << " to " << s2 << ", PLAYER 1 WINS.\n";
    else cout << "SCORE: " << s1 << " to " << s2 << ", PLAYER 2 WINS.\n";
  }

  return 0;
}