Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 위상정렬
- 문자열
- DP
- LIS
- C++1967
- strtok
- 백준 17071
- 순열
- C++ 1918
- Backtracking
- 소트 게임
- C++ 17071
- 가장 긴 증가하는 부분 수열
- BFS
- 조합론
- C++1167
- 다익스트라
- 조합
- C++ 1937
- c언어
- 백준 숨바꼭질5
- C++
- 프로그래머스
- 백준
- 16933
- 알고리즘
- 백트래킹
- 투포인터
- 인덱스 트리
- DFS
Archives
- Today
- Total
블로그
[C++] 2630 : 색종이 만들기 본문
728x90
실버 Ⅲ
#include <iostream>
int arr[128][128] = { 0, };
int N;
int blue = 0;
int white = 0;
void df(int x, int y, int n) {
int half = n / 2;
int cnt = 0;
for (int i = x; i < x + n; i++) {
for (int j = y; j < y + n; j++) {
if (arr[i][j]) cnt++;
}
}
if (cnt == 0) {
white++;
}
else if (cnt == n * n) {
blue++;
}
else {
df(x, y, half);
df(x + half, y, half);
df(x, y + half, half);
df(x + half, y + half, half);
return;
}
}
int main() {
scanf("%d", &N);
int in;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
scanf("%d", &in);
if (in) arr[i][j] = 1;
}
}
df(0, 0, N);
printf("%d\n%d", white, blue);
}
문제 - 1 페이지
www.acmicpc.net
분할 정복 문제..
네모의 왼쪽 끝 지점도 지정해 줘야 하므로
(아니면 그냥 1/4의 크기로 줄어들고 시작 지점은 0,0인 네모만 탐색..)
df(divide function)에 x, y도 건네줌..
'PS' 카테고리의 다른 글
[C++] 1966 : 프린터 큐 (0) | 2021.03.03 |
---|---|
[C++] 2447 : 별 찍기 - 10 (0) | 2021.02.14 |
[C++] 1629 : 곱셈 (0) | 2021.02.13 |
[C++] 14003 : 가장 긴 증가하는 부분 수열 5 (0) | 2021.02.13 |
[C++] 14002 : 가장 긴 증가하는 부분 수열 4 (0) | 2021.02.13 |
Comments