```
백준 1173번 운동 JAVA 구현해보기
```

이번 글을 통해 배워갈 내용
- 백준 1173번 풀이
https://www.acmicpc.net/problem/1173
1173번: 운동
첫째 줄에 다섯 정수 N, m, M, T, R이 주어진다.
www.acmicpc.net
백준 1173번 운동은
난이도 브론즈 등급의 문제로서
초기이자 최소 맥박 값
최대 맥박 값
휴식 시 분당 맥박 감소량
운동 시 분당 맥박 증가량
총 운동 시간이 주어질 때
운동과 휴식시간을 합한 시간의 최솟값을 출력하고
불가능하다면 -1을 출력하면 됩니다.
(맥박은 최대 맥박 값과 최소 맥박값 사이를 유지해야 합니다)
30분 정도 위에 링크를 방문하셔서 풀어보시고
안 풀리시는 경우에만 아래 해답을 봐주시면 감사하겠습니다.
처음에는 공식을 만들어서 풀었으나
통과를 할 수 없어서
운동시간이 분이며 정수 단위로 진행이 돼서
for 문과 조건들을 넣어서 풀었습니다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
// BufferedReader Object 생성
final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// 입력
final StringTokenizer st = new StringTokenizer(br.readLine());
final int totalHealthTime = Integer.parseInt(st.nextToken());
final int initPulse = Integer.parseInt(st.nextToken());
final int thresholdPulse = Integer.parseInt(st.nextToken());
final int increaseInPulsePerMinute = Integer.parseInt(st.nextToken());
final int decreaseInPulsePerMinute = Integer.parseInt(st.nextToken());
int totalTime = -1;
if (thresholdPulse - initPulse >= increaseInPulsePerMinute) {
totalTime = 0;
int currentPulse = initPulse;
for (int cnt = 0; cnt < totalHealthTime; ) {
totalTime++;
if (currentPulse + increaseInPulsePerMinute <= thresholdPulse) {
currentPulse += increaseInPulsePerMinute;
cnt++;
} else {
currentPulse -= decreaseInPulsePerMinute;
if (currentPulse < initPulse) currentPulse = initPulse;
}
}
}
// 출력
System.out.print(totalTime);
// 생성된 BufferedReader 반환
br.close();
}
}
//codemasterkimc.tistory.com [김씨의 코딩 스토리]
읽어주셔서 감사합니다
무엇인가 얻어가셨기를 바라며
오늘도 즐거운 코딩 하시길 바랍니다 ~ :)
728x90
'Java > Java 알고리즘' 카테고리의 다른 글
| 백준 25024번 시간과 날짜 JAVA 구현해보기 (0) | 2022.05.09 |
|---|---|
| 백준 25083번 새싹 JAVA 구현해보기 (0) | 2022.05.09 |
| 백준 1236번 성 지키기 JAVA 구현해보기 (0) | 2022.05.08 |
| 백준 1252번 이진수 덧셈 JAVA 구현해보기 (0) | 2022.05.07 |
| 백준 1225번 이상한 곱셈 JAVA 구현해보기 (0) | 2022.05.07 |