728x90
https://www.acmicpc.net/problem/13300
풀이 방법
수정중..
JAVA 코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BOJ_13300_방배정 {
static StringTokenizer st;
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
st=new StringTokenizer(br.readLine());
int N=Integer.parseInt(st.nextToken());
int K=Integer.parseInt(st.nextToken());
int[][] input=new int[7][2]; //학년,성별
int result=0;
for (int i = 0; i < N; i++) {
st=new StringTokenizer(br.readLine());
int gender=Integer.parseInt(st.nextToken());
int grade=Integer.parseInt(st.nextToken());
input[grade][gender]+=1;
}
for (int i = 1; i < 7; i++) {
for (int j = 0; j < 2; j++) {
if (input[i][j]==0) continue;
else if(input[i][j]<=K) result+=1;
else {
result+=input[i][j]/K;
if(input[i][j]%K!=0) {
result+=1;
}
}
}
}
System.out.println(result);
}
}
분명히 맞게 했다고 생각했는데 계속 2점이 나오길래 고민하다가 답안을 봤다.
원래 코드는 K보다 크면 result+=(input[i][j]/K)+(input[i][j]%K) 였는데, 답안은 (input[i][j]%K)를 해주는 것이 아니라 +1을 해주는 것이였다. 사실 아직 생각해도 왜 +1을 해야하는지 모르겠다. %K랑 똑같은거 아닌가..? ㅠ
728x90
'알고리즘 > 백준 BOJ' 카테고리의 다른 글
[JAVA] 백준 2567 색종이-2 (0) | 2021.08.30 |
---|---|
[JAVA] 백준 2477 참외밭 (1) | 2021.08.29 |
[JAVA] 백준 16236 아기상어 (0) | 2021.08.25 |
[JAVA] 백준 10026 적록색약 (0) | 2021.08.23 |
[JAVA] 백준 1260 DFS와 BFS (0) | 2021.08.23 |