카테고리 없음

백준 22864번 피로도 JAVA 구현해보기

kimc 2022. 8. 23. 21:39

```

백준 22864번 피로도

```

이번 글을 통해 배워갈 내용

  1. 백준 22864번 풀이

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

 

22864번: 피로도

첫 번째 줄에 네 정수 $A$, $B$, $C$, $M$이 공백으로 구분되어 주어진다. 맨 처음 피로도는 0이다.

www.acmicpc.net

 

백준 22864번 피로도는

 

난이도 브론즈 등급의 문제로서

 

일하면

피로도가 시간당 A만큼 증가

업무량은 시간당 B만큼 증가

 

쉬면

피로도가 시간당 C만큼 감소

 

그리고 하루가 24시간이고

최대 감당할 수 있는 피로도가 M일 때

하루 할 수 있는 최대 완수하는 업무량을 구해주면 됩니다.

 


30분 정도 위에 링크를 방문하셔서 풀어보시고

안 풀리시는 경우에만 아래 해답을 봐주시면 감사하겠습니다.


시간이 24시간이 아닐 때 시간을 1만큼 증가해주고

현재 증가되는 피로도와 누적된 피로도가 피로도 허용량을 초과하지 않는다면

일을 하고 일을 함으로써 피로도가 증가하고 업무를 완수하게 됩니다.

 

만약 피로도를 초과한다면

쉬고 피로도를 감소하게 됩니다. 이때 피로도는 0보다 작게 감소할 수는 없습니다.

 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        // 입력
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final String[] input = br.readLine().split(" ");
        int fatigueUpPerHour = Integer.parseInt(input[0]);
        int outputUpPerHour = Integer.parseInt(input[1]);
        int fatigueDownPerHour = Integer.parseInt(input[2]);
        int fatigueThroughput = Integer.parseInt(input[3]);

        // 출력
        System.out.print(findMaxOutput(fatigueUpPerHour, outputUpPerHour, fatigueDownPerHour, fatigueThroughput));
    }

    private static int findMaxOutput(int fatigueUpPerHour,
                                     int outputUpPerHour,
                                     int fatigueDownPerHour,
                                     int fatigueThroughput) {
        int ans = 0;
        int hour = 0;
        int ONE_DAY = 24;
        if (fatigueUpPerHour <= fatigueThroughput) {
            int cumulatedFatigue = 0;
            while (hour != ONE_DAY) {
                hour++;
                if ((cumulatedFatigue + fatigueUpPerHour) <= fatigueThroughput) {
                    ans += outputUpPerHour;
                    cumulatedFatigue += fatigueUpPerHour;
                } else {
                    if ((cumulatedFatigue - fatigueDownPerHour) >= 0) {
                        cumulatedFatigue -= fatigueDownPerHour;
                    } else {
                        cumulatedFatigue = 0;
                    }
                }
            }
        }
        return ans;
    }
}

// https://codemasterkimc.tistory.com

 

 

읽어주셔서 감사합니다

 

무엇인가 얻어가셨기를 바라며

 

오늘도 즐거운 코딩 하시길 바랍니다 ~ :)

 


 

728x90