본문 바로가기
Problem Solving/Baekjoon

[백준] 13170 떨어진 수정 - Greedy / Java

by graycode 2023. 10. 21.

 문제 링크

 

13170번: 떨어진 수정

첫 번째 줄에 네 개의 정수 N, K, P, W가 주어진다. 이는 순서대로 남아있는 마나 수정의 수 N(1 ≤ N ≤ 1,000)과 마나가 응집된 마나 수정의 강도 순위를 나타내는 K(1 ≤ K ≤ N), 둔 망치의 최대 파워 P

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));

        read();
        read();
        int p = read(), w = read();

        bw.write(String.valueOf((p - 1) / w + 1));
        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;
    }

}

댓글