코딩테스트-알고리즘/백준 BOJ

[백준 BOJ/Silver V] 2563번 : 색종이

닉네임생각즁 2024. 1. 23. 12:51

 

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

 

2563번: 색종이

가로, 세로의 크기가 각각 100인 정사각형 모양의 흰색 도화지가 있다. 이 도화지 위에 가로, 세로의 크기가 각각 10인 정사각형 모양의 검은색 색종이를 색종이의 변과 도화지의 변이 평행하도록

www.acmicpc.net

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에 더해주면 답이 된다!!