• 문제 링크
15600번: Boss Battle
You are stuck at a boss level of your favourite video game. The boss battle happens in a circular room with n indestructible pillars arranged evenly around the room. The boss hides behind an unknown pillar. Then the two of you proceed in turns. First, in y
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));
int n = read(), range = 2, tgt = 0;
while ((range - 1) % n != tgt && (range) % n != tgt && (range + 1) != tgt) {
range += 2;
tgt++;
}
bw.write(String.valueOf(Math.max(tgt, 1)));
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;
}
}
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(String.valueOf(Math.max(read() - 2, 1)));
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' 카테고리의 다른 글
[백준] 15008 Falling Apart - Greedy / Java (0) | 2024.03.16 |
---|---|
[백준] 27951 옷걸이 - Greedy / Java (0) | 2024.03.15 |
[백준] 30236 증가 수열 - Greedy / Java (0) | 2024.03.13 |
[백준] 28110 마지막 문제 - Greedy / Java (0) | 2024.03.12 |
[백준] 9329 패스트 푸드 상금 - Greedy / Java (0) | 2024.03.11 |
댓글