백준 2563번: 색종이

hoon·2025년 2월 5일

백준

목록 보기
29/44

package BOJ.step07;

import java.util.Scanner;

public class BOJ2563 {
    public static void main(String[] args) {
        int[][] paper = new int[100][100]; // 도화지 크기 100x100
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();

        for (int t = 0; t < N; t++) {
            int x = sc.nextInt();
            int y = sc.nextInt();

            // 10x10 색종이 부분을 1로 채우기
            for (int i = x; i < x + 10; i++) {
                for (int j = y; j < y + 10; j++) {
                    paper[i][j] = 1;
                }
            }
        }

        // 1이 채워진 부분(색종이가 붙은 영역) 카운트
        int coveredArea = 0;
        for (int i = 0; i < 100; i++) {
            for (int j = 0; j < 100; j++) {
                coveredArea += paper[i][j];
            }
        }

        System.out.println(coveredArea);
    }
}

한칸의 넓이를 1로 생각..

0개의 댓글