게임 1072

LJM·2023년 2월 6일
0

백준풀기

목록 보기
73/259

https://www.acmicpc.net/problem/1072

처음엔 실수형 자료형을 사용했는데 디버깅하다보니 long 형으로 분자만 100을 곱해서 해결하는 방법으로 바꾸게 되었다

import java.io.*;
import java.util.*;

public class Main
{
    public static void main(String[] args)throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] input = br.readLine().split(" ");
        int x = Integer.parseInt(input[0]);
        int y = Integer.parseInt(input[1]);

        int curPer = cal(x, y);

        int left = 0;
        int right = 1000000000;

        int cand = 0;
        int ans = -1;
        while(left <= right)
        {
            cand = (left + right)/2;

            if(curPer < cal(x+cand, y+cand))
            {
                ans = cand;
                right = cand-1;
            }
            else
            {
                left = cand+1;
            }
        }

        System.out.println(ans);
    }

    public static int cal(long x, long y)
    {
        long xcopy = x;
        long ycopy = y*100;
        int ret = (int)(ycopy/xcopy);
        return ret;
    }
}
profile
게임개발자 백엔드개발자

0개의 댓글

Powered by GraphCDN, the GraphQL CDN