[BOJ][C#] 18512 점프 점프

LimJaeJun·2023년 8월 6일
0

PS/BOJ

목록 보기
9/108

📕 문제

📌 링크
문제 사진

📘 코드

namespace BOJ
{
    class No_18512
    {
        static void Main()
        {
            using StreamReader input = new StreamReader(new BufferedStream(Console.OpenStandardInput()));
            using StreamWriter output = new StreamWriter(new BufferedStream(Console.OpenStandardOutput()));

            int[] inputs = Array.ConvertAll(input.ReadLine().Split(), int.Parse);

            int x = inputs[0];
            int y = inputs[1];
            int p1 = inputs[2];
            int p2 = inputs[3];

            int answer = -1;
            int cnt = 0;
            int px = p1, py = p2;
            while(cnt < 1000)
            {
                if(px == py)
                {
                    answer = px;
                    break;
                }

                if(px < py)
                    px += x;
                else
                    py += y;

                cnt++;
            }

            output.WriteLine(answer);
        }
    }
}

📙 오답노트

로직은 다 구현 하였지만 만나지 않는 경우를 어떤식으로 판별할지 하다가 다른 분들의 풀이를 참고하여 1000번 계산했을 때에도 같지 않다면 만나지 않는 경우로 판별하였다.

📒 알고리즘 분류

  • 수학
  • 브루트포스 알고리즘
  • 정수론
profile
Dreams Come True

0개의 댓글

관련 채용 정보