https://www.acmicpc.net/problem/23351
23351번: 물 주기
첫째 줄에 자연수 $N$, $K$, $A$, $B$가 공백을 사이에 두고 주어진다. ($2 \le N \le 100$, $1 \le K \le 100$, $1 \le A \times B < N$, $A$는 $N$의 약수)
www.acmicpc.net
package BOJ.simulation;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.function.Function;
public class BOJ_23351 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
Function<String,Integer> stoi = Integer::parseInt;
int n = stoi.apply(st.nextToken());
int k = stoi.apply(st.nextToken());
int a = stoi.apply(st.nextToken());
int b = stoi.apply(st.nextToken());
int period = n/a;
if(n % a != 0){
period++;
}
int result = cal(k,b,period);
System.out.println(result);
}
private static int cal(int k, int water, int period){
if(k < period){
return k;
}
int result = 0;
while(true){
k -= period;
if(k < 0){
return result + period + k;
}
k += water;
result += period;
}
}
}
'알고리즘' 카테고리의 다른 글
백준 10711번 모래성 (JAVA) (0) | 2023.03.09 |
---|---|
백준 17271번 리그 오브 레전설 (JAVA) (0) | 2023.03.08 |
백준 1347번 미로 만들기 (JAVA) (0) | 2023.03.06 |
프로그래머스 최댓값 만들기 (JAVA) (0) | 2023.03.05 |
백준 13265번 색칠하기 (JAVA) (0) | 2023.03.04 |