main
[백준-2839번/Java] 설탕배달 본문
* 다이나믹 프로그래밍
* 그리디 알고리즘
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int sugar = sc.nextInt();
int five_q = sugar / 5;
int five_r = sugar % 5;
int three_q = 0;
while (true) {
if (five_r == 1) {
five_q -= 1;
three_q += 2;
} else if (five_r == 2) {
five_q -= 2;
three_q += 4;
} else if (five_r == 3) {
three_q++;
} else if (five_r == 4) {
five_q -= 1;
three_q += 3;
}
break;
}
if (five_q >= 0 && three_q >= 0) {
System.out.println(five_q + three_q);
} else {
System.out.println(-1);
}
sc.close();
}
}
728x90
'Algorithm' 카테고리의 다른 글
[백준-5622번/Java] 다이얼 (0) | 2022.11.11 |
---|---|
[백준-1920번/Java] 수 찾기 (0) | 2022.11.11 |
[백준-2869번/Java] 달팽이는 올라가고 싶다. (0) | 2022.11.10 |
[백준-2751번/Java] 수 정렬하기 2 (0) | 2022.11.10 |
[백준-2750번/Java] 수 정렬하기 (0) | 2022.11.10 |
Comments