본문 바로가기
Problem Solving/BOJ

백준 - 10163 색종이

by 채니_ 2021. 2. 22.

www.acmicpc.net/problem/10163

 

10163번: 색종이

평면에 색깔이 서로 다른 직사각형 모양의 색종이 N장이 하나씩 차례로 놓여진다. 이때 색종이가 비스듬하게 놓이는 경우는 없다. 즉, 모든 색종이의 변은 서로 평행하거나, 서로 수직이거나 둘

www.acmicpc.net


2차원 배열의 값을 cnt배열의 인덱스로 활용하여 풀었다.


import java.util.Arrays;
import java.util.Scanner;

public class BJ색종이 {
	static  int [][]arr;
	static int []cnt;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();//색종이의 장수
		arr = new int [100+1][100+1];
		cnt = new int[N+1];//cnt 0 인덱스는 버림
        
		for (int n = 1; n <= N; n++) {//종이수만큼반복
			
			int r = sc.nextInt();//왼쪽위의 좌표 r,c
			int c = sc.nextInt();
			int row = sc.nextInt();//높이
			int col = sc.nextInt();//너비
			
			for (int i = r; i <r+row; i++) {
				for (int j = c; j <c+col; j++) {
					arr[i][j]=n; // n = 1,2,3,,
				}
			}
		}
		//개수세기
		for (int i = 0; i < arr.length; i++) {
			for (int j = 0; j < arr.length; j++) {
				
					cnt[arr[i][j]]++; // cnt[1]++ cnt[2]++ ,,
				
			}
		}
		for (int i = 1; i < cnt.length; i++) {
			System.out.println(cnt[i]); // cnt[1]~ cnt[3]까지 출력
		}

	}

}

'Problem Solving > BOJ' 카테고리의 다른 글

백준- 8911 거북이  (0) 2021.03.07
백준- 13300 방 배정  (0) 2021.02.22
백준- 2606번 바이러스  (0) 2021.02.21
백준 -1931 회의실 배정  (0) 2021.02.21
백준- 4963 섬의 개수  (0) 2021.02.21

댓글