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 |
Tags
- 스프링 입문
- Spring
- HTTP
- C++
- FIFO paging
- 우아한 테크 세미나
- 제프리리처
- Window-Via-c/c++
- OS
- Operating System
- 열혈 TCP/IP 소켓 프로그래밍
- inflearn
- 이펙티브코틀린
- n타일링2
- 토마토
- 열혈 tcp/ip 프로그래밍
- 운영체제
- 윤성우 저자
- BOJ
- Operating System.
- 우아한레디스
- TCP/IP
- 스프링 핵심 원리
- Four Squares
- redis
- C#
- 에러핸들링
- 김영한
- 2475번
- 10026번
Archives
- Today
- Total
나의 브을로오그으
[c++] 1992번 : 쿼드트리 본문
https://www.acmicpc.net/problem/1992
#include <iostream>
#include <string>
using namespace std;
#define MAX_SIZE 65
bool IsSameValue(bool matrix[][65], int x, int y, int len);
void QuadTree(bool matrix[][65], int x, int y, int len, string* result);
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
string result;
result.reserve(MAX_SIZE * MAX_SIZE * 5);
bool matrix[MAX_SIZE][MAX_SIZE] = { false, };
int N = 0;
char input[MAX_SIZE] = { 0, };
cin >> N;
cin.ignore();
for (int i = 1; i <= N; ++i)
{
cin.getline(input, MAX_SIZE);
for (int j = 1; j <= N; ++j)
{
matrix[i][j] = input[j - 1] - '0';
}
}
QuadTree(matrix, 1, 1, N, &result);
cout << result << '\n';
return 0;
}
bool IsSameValue(bool matrix[][65], int x, int y, int len)
{
bool value = matrix[y][x];
for (int i = y; i < y + len; ++i)
{
for (int j = x; j < x + len; ++j)
{
if (matrix[i][j] != value)
{
return false;
}
}
}
return true;
}
void QuadTree(bool matrix[][65], int x, int y, int len, string* result)
{
if (len == 1 || IsSameValue(matrix, x, y, len) == true)
{
int n = matrix[y][x] == true ? 1 : 0;
result->append(to_string(n));
}
else
{
result->append("(");
// todo quadtree
int half = len / 2;
QuadTree(matrix, x, y, half, result);
QuadTree(matrix, x + half, y, half, result);
QuadTree(matrix, x, y + half, half, result);
QuadTree(matrix, x + half, y + half, half, result);
result->append(")");
}
return;
}
'알고리즘 > BaekJoon' 카테고리의 다른 글
[c++] 2579번 : 계단 오르기 (0) | 2022.06.27 |
---|---|
[c++] 2178번 : 미로 탐색 (0) | 2022.06.23 |
[c++] 1931번 : 회의실 배정 (0) | 2022.06.22 |
[c++] 1927번 : 최소 힙 (0) | 2022.06.21 |
[c++] 1764번 : 듣보잡 (0) | 2022.06.15 |