• 문제 링크
14697번: 방 배정하기
정보 초등학교 6학년 여학생들은 단체로 2박 3일 수학여행을 가기로 했다. 학생들이 묵을 숙소에는 방의 정원(방 안에 있는 침대 수)을 기준으로 세 종류의 방이 있으며, 같은 종류의 방들이 여러
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
bw.write(isPossible(read(), read(), read(), read()));
bw.flush();
}
private static String isPossible(int a, int b, int c, int n) {
for (int i = 0; i <= n / a; i++)
for (int j = 0; j <= n / b; j++)
for (int k = 0; k <= n / c; k++)
if (a * i + b * j + c * k == n) return "1";
return "0";
}
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' 카테고리의 다른 글
[백준] 1773 폭죽쇼 - Brute Force / Java (0) | 2023.12.26 |
---|---|
[백준] 1233 주사위 - Brute Force / Java (0) | 2023.12.25 |
[백준] 30019 강의실 예약 시스템 - Greedy / Java (0) | 2023.12.23 |
[백준] 11968 High Card Wins - Greedy / Java (0) | 2023.12.22 |
[백준] 16406 Exam - Greedy / Java (0) | 2023.12.21 |
댓글