[백준 1992번] 쿼드트리 (C++)

2023. 10. 21. 15:49·PS/백준 알고리즘[BOJ]
728x90

//white: 0, black: 1
#define SIZE 64
#include<iostream>
#include<string>
#include<cstdlib>

using namespace std;
char col;
char map[SIZE][SIZE];
// change - true, not change - false
bool check(int x1, int y1, int x2, int y2) {
	col = map[x1][y1];
	for (int i = x1; i < x2; i++) {
		for (int j = y1; j < y2; j++) {
			if (col != map[i][j]) return true;
		}
	}
	return false;
}

void dc(int size, int x, int y) {
	if (size == 1) {
		cout << map[x][y];
		return;
	}
	if (!check(x, y, x + size, y + size)) {
		cout << map[x][y];
		return;
	}
	size /= 2;
	cout << '(';
	dc(size, x, y);
	dc(size, x + size, y);
	dc(size, x, y + size);
	dc(size, x + size, y + size);
	cout << ')';
}

int main(void) {
	cin.tie(0);
	ios_base::sync_with_stdio(NULL);
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		string str;
		cin >> str;
		for (int j = 0; j < N; j++) map[j][i] = str[j];
	}
	dc(N, 0, 0);
	return 0;
}
728x90

'PS > 백준 알고리즘[BOJ]' 카테고리의 다른 글

[백준 10830번] 행렬 제곱 (C++)  (0) 2023.10.21
[백준 1780번] 종이의 개수 (C++)  (0) 2023.10.21
[백준 2630번] 색종이 만들기 (C++)  (0) 2023.10.20
[백준 1074번] Z (C++)  (0) 2023.10.18
[백준 10799번] 쇠막대기 (C++)  (0) 2023.10.12
'PS/백준 알고리즘[BOJ]' 카테고리의 다른 글
  • [백준 10830번] 행렬 제곱 (C++)
  • [백준 1780번] 종이의 개수 (C++)
  • [백준 2630번] 색종이 만들기 (C++)
  • [백준 1074번] Z (C++)
BE_개발자
BE_개발자
경이로운 BE 개발자가 되기 위한 프로그래밍 공부 기록장
    250x250
  • BE_개발자
    경이로운 개발일기
    BE_개발자
  • 전체
    오늘
    어제
    • 전체 보기 (213)
      • AI (1)
        • AI native (0)
        • Skill (0)
      • SpringBoot (4)
        • JPA (3)
        • Security (0)
        • 튜토리얼 (1)
        • 기타 (0)
      • Infra (0)
        • Docker (0)
        • AWS (0)
        • NCP (0)
        • GCP (0)
      • React (19)
      • 서버 (0)
      • Computer Science (16)
        • SW Engineering (10)
        • Data Base (2)
        • OS(운영 체제) (4)
      • Data science (0)
        • Probability & Random Variab.. (0)
        • Data Analysis(데이터 분석) (0)
      • 자료구조 | 알고리즘 (57)
        • 선형 자료구죠 (6)
        • 비선형 자료구조 (9)
        • 정렬(Sort) (3)
        • 탐색(Brute Force) (7)
        • 분할 정복(Devide Conquer) (3)
        • 동적 계획법 (6)
        • 탐욕(Greedy) (2)
        • 수학 (7)
        • 심화 알고리즘 (10)
      • PS (44)
        • 백준 알고리즘[BOJ] (38)
        • 프로그래머스[programmers] (3)
      • Dev tool (15)
        • 개발 도구 및 환경 (0)
        • vscode (3)
        • Git Hub (4)
        • Chrome 웹스토어 (5)
        • Python 전용 개발환경 (0)
      • 성장기록 (1)
      • 개인 project (14)
        • 홈페이지 만들기 (11)
        • 냉보미 (1)
      • STL(Standard Library) (9)
      • programming Language (1)
        • javascript (1)
      • 기타 (13)
        • html css (11)
      • (책, 글, 블로그)리뷰 (3)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

    • 백준
    • Github
    • Notion
    • 서울과학기술대학교 학술동아리 EC
  • 공지사항

  • 인기 글

  • 태그

    프론트엔드
    수학
    스프링부트
    BFS
    괄호쌍
    자료구조
    SW 공학
    PS
    stack
    이분 탐색
    탐색
    OS
    SW Engineering
    백준
    운영체제
    stl
    완전 탐색
    백트래킹
    react
    스택
    알고리즘
    DP
    순열
    그리디
    브루트포스
    CS
    C++
    비트마스킹
    재귀함수
    분할정복
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.6
BE_개발자
[백준 1992번] 쿼드트리 (C++)
상단으로

티스토리툴바