30분
수학, 구현
284ms
- 학생의 성별, 학년에 따른 배열 생성
- 입력 들어오면 해당 인덱스에 +1
for (int i = 0; i < N; i++) {
int gender = sc.nextInt();
int grade = sc.nextInt();
arr[gender][grade]++; //각 배열값의 빈도수(해당 학년/성별의 학생 수)
}
- 각 인덱스당 학생 수를 K로 나누기
- 이때, 나머지가 0이 아닐 경우(딱 떨어지지 않을 경우) +1
for(int i=0; i<2; i++) {
for (int j = 1; j <= 6; j++) {
count += arr[i][j] / K;
if (arr[i][j]%K != 0) {
count++;
}
}
}
- 크게 어렵지 않은 문제였다.
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt(); //학생 수
int K = sc.nextInt(); //한 방 최대 인원 수
int[][] arr = new int[2][7];
int count = 0;
for (int i = 0; i < N; i++) {
int gender = sc.nextInt();
int grade = sc.nextInt();
arr[gender][grade]++; //각 배열값의 빈도수(해당 학년/성별의 학생 수)
}
for(int i=0; i<2; i++) {
for (int j = 1; j <= 6; j++) {
count += arr[i][j] / K;
if (arr[i][j]%K != 0) {
count++;
}
}
}
System.out.println(count);
}
}