Algorithm
[백준-2563번/Java] 색종이
1984
2022. 11. 13. 00:32
* 색종이를 붙이는 판을 배열로 구현했다.
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
Scanner scan = new Scanner(System.in);
int[][] board = new int[100][100];
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
board[j][i] = 0;
}
}
int N = scan.nextInt();
for (int k = 0; k < N; k++) {
int x1 = scan.nextInt();
int y1 = scan.nextInt();
int x2 = x1 + 10;
int y2 = y1 + 10;
for (int i = y1 - 1; i < y2 - 1; i++) {
for (int j = x1 - 1; j < x2 - 1; j++) {
board[j][i] = 1;
}
}
}
int count = 0;
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
if (board[j][i] == 1) {
count++;
}
}
}
System.out.println(count);
scan.close();
}
}
728x90