코딩테스트-알고리즘/백준 BOJ
[백준 BOJ/Silver V] 2563번 : 색종이
닉네임생각즁
2024. 1. 23. 12:51
https://www.acmicpc.net/problem/2563
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt(); // 색종이 수
boolean[][] paper = new boolean[100][100];
int index = 0;
int result = 0;
while(index<N) {
int X = sc.nextInt(); // x축
int Y = sc.nextInt(); // y축
for(int i = Y; i< Y+10; i++) {
for(int j = X; j < X+10; j++) {
paper[i][j] = true;
}
}
index++;
}
//System.out.println(Arrays.deepToString(paper));
for(int i = 0; i< 100; i++) {
for(int j = 0; j < 100; j++) {
if (paper[i][j]) result++;
}
}
System.out.println(result);
}
}
색종이가 붙은 영역을 true로 표시해서 boolean 배열을 완성하고
전체 배열을 돌면서 true가 나올때마다 result에 더해주면 답이 된다!!