• 문제 링크
16200번: 해커톤
예를 들어, 5명의 학생이 있고, X1 = 1, X2 = 2, X3 = 5, X4 = 2, X5 = 1인 경우에 팀의 수의 최솟값은 4이다. {1}, {2}, {3}, {4}, {5}로 5개의 팀을 만드는 방법이 있지만, 이것은 팀의 수가 최소가 아니다. {1}, {3}
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = read();
int[] arr = new int[n];
while (n-- > 0) arr[n] = read();
Arrays.sort(arr);
int cnt = 0;
for (int i = 0; i < arr.length; i += arr[i]) cnt++;
bw.write(String.valueOf(cnt));
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 25972 도미노 무너트리기 - Greedy / Java (0) | 2024.02.15 |
---|---|
[백준] 16237 이삿짐센터 - Greedy / Java (0) | 2024.02.14 |
[백준] 14720 우유 축제 - Greedy / Java (0) | 2024.02.12 |
[백준] 27940 가지 산사태 - Greedy / Java (0) | 2024.02.11 |
[백준] 27563 Moo Operations - Greedy / Java (0) | 2024.02.10 |
댓글