• 문제 링크
28063번: 동전 복사
돈이 없어 슬픈 레이무는 어느 날, 한 기계를 발견했다. 이 기계는 한 변의 길이가 \(N\)인 정사각형 모양이고, \(1 \times 1\) 크기의 정사각형 칸들로 이루어져 있다. 각 칸의 위치는 좌표로 나타낼
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(), x = read(), y = read();
if (n == 1) bw.write("0");
else if ((x == 1 || x == n) && (y == 1 || y == n)) bw.write("2");
else if (x == 1 || x == n || y == 1 || y == n) bw.write("3");
else bw.write("4");
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' 카테고리의 다른 글
[백준] 27961 고양이는 많을수록 좋다 - Greedy / Java (0) | 2023.08.25 |
---|---|
[백준] 2930 가위 바위 보 - Greedy / Java (0) | 2023.08.24 |
[백준] 5002 도어맨 - Greedy / Java (0) | 2023.08.22 |
[백준] 15786 Send me the money - Greedy / Java (0) | 2023.08.21 |
[백준] 19564 반복 - Greedy / Java (0) | 2023.08.20 |
댓글