• 문제 링크
15721번: 번데기
예를 들어 7명이 있고, 16번째 등장하는 “뻔”을 부른 사람의 번호를 알고 싶다면 입력은 7 16 0이다. 4명이 있고 6번째 등장하는 “데기”를 부른 사람의 번호를 알고 싶다면 입력은 4 6 1이며, 이
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;
public class Main {
static int t, b, n, r = 2;
static Map<Integer, Integer> map = new HashMap<Integer, Integer>() {{
put(0, 0);
put(1, 0);
}};
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int a = read();
t = read();
b = read();
while (loop()) r++;
bw.write(String.valueOf(n % a));
bw.flush();
}
private static boolean loop() {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++, n++) {
map.put(j, map.get(j) + 1);
if (b == j && map.get(j) == t) return false;
}
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < r; j++, n++) {
map.put(i, map.get(i) + 1);
if (b == i && map.get(i) == t) return false;
}
}
return true;
}
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' 카테고리의 다른 글
[백준] 15098 No Duplicates - Data Structure / Java (0) | 2023.09.07 |
---|---|
[백준] 6159 Costume Party - Brute Force / Java (0) | 2023.09.06 |
[백준] 1895 필터 - Brute Force / Java (0) | 2023.09.04 |
[백준] 2993 세 부분 - Brute Force / Java (0) | 2023.09.03 |
[백준] 1816 암호 키 - Brute Force / Java (1) | 2023.09.02 |
댓글