문제 풀이
문제는 조금 쉬운 난이도이지만 처음 배우는 그리디 알고리즘을 익히고 적용하는데 시간이 걸렸습니다.
#그리디 알고리즘 학습 , BufferedReader ,StringBuilder 사용 방법 숙지 , 자바 풀이
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int N = Integer.parseInt(br.readLine());
int count = 0;
int inx = 0;
int[] check = { 5, 3 };
int bool = 0;
int save = N;
while (bool != 1) {
count += N / check[inx];
N %= check[inx];
inx++;
if (N == 1 || N == 2) {
count = save / 5;
int c= 0;
while(c != 1) {
if(count -1 < 0) {
c = 1;
bool = 1;
count = -1;
break;
}
int x= (save-5*(count-1))%3;
if(x == 0) {
count = (count-1)+ (save-5*(count-1))/3;
c = 1;
bool = 1;
}
else if(count == 0 && x != 0 ) {
count = -1;
bool = 1;
c = 1;
}
else {
count --;
}
}
}
else if( N == 0) {
bool = 1;
}
}
System.out.println(count);
}
}
'모각코 > 2021_summer_모각코' 카테고리의 다른 글
2021_summer_모각코] LIE 또! 팀 - 4차시 결과 (0) | 2021.07.28 |
---|---|
2021_summer_모각코] LIE 또! 팀 - 4차시 계획 (0) | 2021.07.28 |
2021_summer_모각코] LIE 또! 팀 - 3차시 계획 (0) | 2021.07.21 |
2021_summer_모각코] LIE 또! 팀 - 2차시 결과 (0) | 2021.07.14 |
2021_summer_모각코] LIE 또! 팀 - 2차시 계획 (0) | 2021.07.14 |
댓글