Notice
Recent Posts
Recent Comments
Link
«   2025/12   »
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
관리 메뉴

main

[백준-2563번/Java] 색종이 본문

Algorithm

[백준-2563번/Java] 색종이

1984 2022. 11. 13. 00:32

* 색종이를 붙이는 판을 배열로 구현했다.

import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);
		int[][] board = new int[100][100];

		for (int i = 0; i < 100; i++) {
			for (int j = 0; j < 100; j++) {
				board[j][i] = 0;
			}
		}
		
		int N = scan.nextInt();

		for (int k = 0; k < N; k++) {
			int x1 = scan.nextInt();
			int y1 = scan.nextInt();
			int x2 = x1 + 10;
			int y2 = y1 + 10;

			for (int i = y1 - 1; i < y2 - 1; i++) {
				for (int j = x1 - 1; j < x2 - 1; j++) {
					board[j][i] = 1;
				}
			}
		}

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

		System.out.println(count);

		scan.close();
	}

}
728x90

'Algorithm' 카테고리의 다른 글

[백준-2581번/Java] 소수  (0) 2022.11.13
[백준-2564번/Java] 경비원  (0) 2022.11.13
[백준-1004번/Java] 어린왕자  (0) 2022.11.12
[백준-2775번/Java] 부녀회장이 될테야  (0) 2022.11.12
[백준-2108번/Java] 통계학  (0) 2022.11.12
Comments