Problem Solving/Baekjoon

[백준] 1980 햄버거 사랑 - Brute Force / Java

graycode 2024. 4. 23. 19:37

 문제 링크

 

1980번: 햄버거 사랑

민혁이는 타워버거와 불고기버거를 매우 좋아한다. 민혁이는 타워버거를 먹는데 n분이 걸리고, 불고기버거를 먹는데 m분이 걸린다. 그는 t분 동안 햄버거를 최대한 많이 먹으려고 한다. 햄버거

www.acmicpc.net

 

 풀이 코드

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        int n = read(), m = read(), min = Math.min(n, m), max = Math.max(n, m), t = read(), i = 0, b = 0, c = 10000;
        do {
            int sub = t - max * i, tb = sub / min + i, tc = sub % min;

            if (tc < c || tb > b) {
                b = tb;
                c = tc;
            }
        } while (max * ++i <= t);

        bw.write(b + " " + c);
        bw.flush();
    }

    private static int read() throws IOException {
        int c, n = System.in.read() & 15;
        while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);

        return n;
    }

}