알고리즘/백준저지
백준저지 10163번 색종이
anott
2021. 8. 29. 22:56
출처: https://www.acmicpc.net/problem/10163
10163번: 색종이
평면에 색깔이 서로 다른 직사각형 모양의 색종이 N장이 하나씩 차례로 놓여진다. 이때 색종이가 비스듬하게 놓이는 경우는 없다. 즉, 모든 색종이의 변은 서로 평행하거나, 서로 수직이거나 둘
www.acmicpc.net
제출 날짜: 2021년 8월 28일 토요일
생각
백준저지 2563번 색종이 문제(https://www.acmicpc.net/problem/2563)와 거의 동일하게 풀었다.
코드
// 출처: 백준저지 10163번 색종이 https://www.acmicpc.net/problem/10163
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int[][] map = new int[1002][1002];
static int N;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
int x1 = Integer.parseInt(st.nextToken());
int y1 = Integer.parseInt(st.nextToken());
int w = Integer.parseInt(st.nextToken());
int h = Integer.parseInt(st.nextToken());
colorMap(i + 1, x1, y1, (x1 + w - 1), (y1 + h - 1));
}
for (int i = 0; i < N; i++) {
countMap(i + 1);
}
}
private static void colorMap(int n, int x1, int y1, int x2, int y2) {
for (int i = x1; i <= x2; i++) {
for (int j = y1; j <= y2; j++) {
map[i][j] = n;
}
}
}
private static void countMap(int n) {
int cnt = 0;
for (int i = 0; i < 1002; i++) {
for (int j = 0; j < 1002; j++) {
if (map[i][j] == n) {
cnt++;
}
}
}
System.out.println(cnt);
}
}