Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: BOJ 1992 쿼드트리 #40

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
063c09a
Add @Parkjju as a contributor
Parkjju Jul 15, 2022
10f5a89
Add @4923 as a contributor
Parkjju Jul 15, 2022
56214e2
Add @4923 as a contributor
Parkjju Jul 15, 2022
c5fec1f
Add @Parkjju as a contributor
Parkjju Jul 15, 2022
81189c1
Add @hotsun1508 as a contributor
Parkjju Jul 15, 2022
dd1da96
Add @HajunYoo as a contributor
Parkjju Jul 15, 2022
86b2664
Add @wJJin as a contributor
Parkjju Jul 15, 2022
62fa6d5
Add @Hellol77 as a contributor
Parkjju Jul 15, 2022
4535c23
Add @SeolHuiGwan9478 as a contributor
Parkjju Jul 15, 2022
3d098ed
📝 docs: all-contributors CLI yarn 패키지 설치
Parkjju Jul 15, 2022
b4a2836
📝 docs: contributorsPerLine 프로퍼티 4 -> 7로 수정
Parkjju Jul 15, 2022
a543d6d
📝 docs(yarn all-contributors generate, 최신데이터 반영): yarn all-contributo…
Parkjju Jul 15, 2022
8f8e41e
📝 docs: url 그대로 노출되는 문제
Parkjju Jul 15, 2022
60c1000
🐛 fix: 뱃지 위치 수정
Parkjju Jul 15, 2022
42eefae
📝 docs: hufslion 이미지 위치 수정
Parkjju Jul 15, 2022
d39d2e6
Merge branch 'docs/contributor'
Parkjju Jul 15, 2022
e6a3553
Add @hotsun1508 as a contributor
Parkjju Jul 15, 2022
6add591
📝 docs: boj 11729 하노이 탑 이동 순서
Parkjju Jul 16, 2022
3b20fb7
📝 docs: boj 11729 시간초과 에러 해결
Parkjju Jul 16, 2022
8ec93fe
Merge branch 'hufslion10th:main' into main
Parkjju Jul 18, 2022
0da0b6d
📝 docs: boj 1074 Z - 헬퍼메서드 활용 표현
Parkjju Jul 18, 2022
4d8673c
📝 docs: boj 1074 Z
Parkjju Jul 18, 2022
cd227ba
Merge branch 'hufslion10th:main' into main
Parkjju Jul 20, 2022
0d5279a
Merge branch 'hufslion10th:main' into main
Parkjju Jul 22, 2022
bf54ffe
Merge branch 'hufslion10th:main' into main
Parkjju Jul 22, 2022
33cd7ad
Merge branch 'hufslion10th:main' into main
Parkjju Jul 26, 2022
66564db
📝 docs: boj 1992 쿼드트리
Parkjju Jul 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions BOJ/1992/parkjju.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const fs = require('fs');
const input = fs.readFileSync('./input.txt').toString().trim().split('\n');

// 변의 길이
const size = +input[0];

// 쿼드트리 저장 공간
const quadTree = input.slice(1, size + 1);

const solution = (row, col, line) => {
// 더 이상 압축할 수 없으면 해당 문자열 리턴
if (size === 1) {
return quadTree[row][col];
}

// 사각형 맨 처음 값
const initValue = quadTree[row][col];

// 내부 요소 중 다른 값 포함여부 플래그
let bool = true;

// 전체 요소 순회
for (let i = row; i < row + line; i++) {
for (let j = col; j < col + line; j++) {
// 다른 값이 섞여있으면 순회 중단
if (quadTree[i][j] !== initValue) {
bool = false;
break;
}
}
if (!bool) {
break;
}
}

// 전체 값이 동일하면 초기값 리턴
if (bool) {
return initValue;
}

// 네 조각으로 쪼개기
const halfSize = line / 2;

// 네 조각으로 쪼갠 후 결과문자열
let result = '';

// 네 조각 순회
for (let i = 0; i < 2; i++) {
for (let j = 0; j < 2; j++) {
// 한 조각마다 순회 결과를 문자열 변수에 push
const pressed = `${solution(
row + i * halfSize,
col + j * halfSize,
halfSize
)}`;
result += pressed;
}
}
// 템플릿 리터럴로 네 조각에 대한 압축결과를 리턴
return `(${result})`;
};

console.log(solution(0, 0, size));