[BOJ][C#] 13411 하늘에서 정의가 빗발친다!

LimJaeJun·2023년 11월 28일
0

PS/BOJ

목록 보기
51/108

📕 문제

📌 링크

📗 접근 방식

  • 입력받은 좌표와 (0,0)사이의 거리를 v로 나눈값(즉, 도달하는데까지 걸리는 시간)을 인덱스와 함께 리스트에 저장
  • 시간순으로 정렬후 같은 시간이 있다면 인덱스를 기준으로 정렬
  • 리스트를 순차적으로 출력

📘 코드

using System.Text;

namespace BOJ_13411
{
    class Program
    {
        static void Main()
        {
            StringBuilder sb = new StringBuilder();
            int n = int.Parse(Console.ReadLine());
            List<(int, double)> list = new List<(int, double)>(); // index, sec
            for (int i = 0; i < n; i++)
            {
                int[] inputs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                double length = Math.Sqrt(inputs[0] * inputs[0] + inputs[1] * inputs[1]);
                list.Add((i + 1, length / inputs[2]));
            }

            var sorted = list.OrderBy(x => x.Item2).ThenBy(x => x.Item1).ToList();

            foreach (var item in sorted)
            {
                sb.AppendLine($"{item.Item1}");
            }

            Console.Write(sb);
        }
    }
}

📙 오답노트

  1. Math.Sqrt()를 사용하지 않고 제출하여서 틀렸다.
  2. Math.Sqrt()를 사용하고 int로 수정하여 틀렸다.

📒 알고리즘 분류

  • 정렬
  • 기하학
  • 피타고라스 정리
profile
Dreams Come True

0개의 댓글

관련 채용 정보