반응형
Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

배움과 기록의 장

[백준] 2563번: 색종이 (Java) 본문

problem solving

[백준] 2563번: 색종이 (Java)

chaeunii 2023. 3. 9. 22:51

✅ 문제

https://www.acmicpc.net/problem/2563

 

✅ 풀이

  • 전체 100x100 보드를 나타내는 2차원 배열을 만들어준다. 각 요소의 초기값은 0.
  • 입력값으로 left와 bottom 값을 받고, left ~ left+10, bottom ~ bottom+10에 해당하는 영역에 1을 할당해준다. (이 과정을 색종이 수 만큼 반복)
  • 100x100 보드를 나타내는 2차원 배열 전체를 순회하며, 요소의 값이 1인 것을 찾아 count 해주면 색종이가 붙은 검은 영역의 넓이를 구할 수 있다.
  •  

 

✅ 코드

import java.util.Scanner;

public class Main{
    public static void main(String[] args){


        Scanner sc = new Scanner(System.in);

        int[][] board = new int[100][100];

        int num = sc.nextInt();
        for(int i = 0; i < num; i++){

            int left = sc.nextInt();
            int bottom = sc.nextInt();

            for(int j= left; j < left+10; j++){
                for(int k = bottom; k < bottom+10; k++){
                    board[j][k] = 1;
                }
            }

        }

        int count = 0;
        for(int i = 0; i < 100; i++){
            for(int j = 0; j < 100; j++){
                if(board[i][j] == 1) count++;
            }
        }
        System.out.println(count);
        
    }
}

 

 

 

반응형