문제링크
https://www.acmicpc.net/problem/2563
문제 풀이
- 도화지를 2차원 배열로 표현: 크기가 100x100인 boolean 배열을 생성
- 색종이를 도화지에 붙이기: 입력받은 좌표를 바탕으로 색종이가 붙는 영역을 true로 설정
- 검은 영역의 넓이 계산: 배열에서 true인 값의 개수를 세어 출력
코드
import java.util.Scanner;
public class BlackPaperArea {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// 도화지 크기 정의
boolean[][] canvas = new boolean[100][100];
// 색종이 수 입력
int n = scanner.nextInt();
// 색종이 붙이기
for (int i = 0; i < n; i++) {
int x = scanner.nextInt();
int y = scanner.nextInt();
// 색종이는 10x10 크기이므로 해당 영역을 true로 설정
for (int dx = 0; dx < 10; dx++) {
for (int dy = 0; dy < 10; dy++) {
canvas[x + dx][y + dy] = true;
}
}
}
// 검은 영역의 넓이 계산
int area = 0;
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
if (canvas[i][j]) {
area++;
}
}
}
System.out.println(area);
scanner.close();
}
}
'알고리즘' 카테고리의 다른 글
[PYTHON/파이썬] 백준 BAEKJOON 14888번 연산자 끼워넣기 (1) | 2024.09.07 |
---|---|
[PYTHON/파이썬] 백준 BAEKJOON 2609번 최대공약수와 최소공배수 (0) | 2024.08.19 |
[JAVA/자바] 백준 BAEKJOON 3048번 개미 (0) | 2024.08.18 |
[PYTHON/파이썬] 백준 BAEKJOON 2460번 지능형 기차 2 (0) | 2024.08.16 |
[JAVA/자바] 백준 BAEKJOON 10798번 세로읽기 (0) | 2024.08.15 |