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

BOJ 1074 Z #27

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 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
a257c78
📝 docs: boj 1072 Z
Parkjju Jul 18, 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
61 changes: 61 additions & 0 deletions BOJ/1074/parkjju.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

// 전역변수로 쓰레기값을 선언할 수 없기 때문에 undefined 선언
let input = undefined;
rl.on('line', (line) => {
// 데이터 정제
input = line
.trim()
.split(' ')
.map((item) => +item);
rl.close();
}).on('close', () => {
// 함수 호출
console.log(helper(input[0], input[1], input[2]));
process.exit();
});

const helper = (N, r, c) => {
// 2*2사이즈일때 행 / 열 판단하여 0,1,2,3값 리턴
if (N === 1) {
if (r === c && r === 0) {
return 0;
} else if (r < c) {
return 1;
} else if (r > c) {
return 2;
} else {
return 3;
}
}

if (r < 2 ** (N - 1) && c < 2 ** (N - 1)) {
// 행 / 열이 1사분면일때
// 사각형 사이즈만 2^(N-1) by 2^(N-1)로 줄인다.
const temp = helper(N - 1, r, c);
return temp;
} else if (r < 2 ** (N - 1) && c >= 2 ** (N - 1)) {
// 행 / 열이 2사분면일때
// 1사분면 사이즈만큼 숫자를 더해주고
// 재귀적으로 2사분면에서의 행 / 열 위치값을 계산해준다.
const temp = helper(N - 1, r, c - 2 ** (N - 1)) + (2 ** (N - 1)) ** 2;
return temp;
} else if (r >= 2 ** (N - 1) && c < 2 ** (N - 1)) {
// 행 / 열이 3사분면일때
// 1,2사분면 사이즈를 합친 것 만큼 숫자를 더해주고
// 재귀적으로 3사분면에서의 행 / 열 위치값을 계산해준다.
const temp =
helper(N - 1, r - 2 ** (N - 1), c) + (2 ** (N - 1)) ** 2 * 2;
return temp;
} else {
// 동일
const temp =
helper(N - 1, r - 2 ** (N - 1), c - 2 ** (N - 1)) +
(2 ** (N - 1)) ** 2 * 3;
return temp;
}
};
53 changes: 53 additions & 0 deletions BOJ/11729/parkjju.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 데이터 정제
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

// 출발지점, 거쳐가는 지점, 도착 지점
let start = 0;
let mid = 1;
let end = 2;
let board = 0;

rl.on('line', (line) => {
// board : 원판 개수
board = +line;
rl.close();
}).on('close', () => {
// start에서 출발하여
// mid를 거쳐
// end까지
// board개 만큼의 원판을 옮긴다.
hanoi(start, mid, end, board);

process.exit();
});

const hanoi = (start, mid, end, boardCount) => {
let answer = [];
const helper = (start, mid, end, boardCount) => {
// 옮길 블록이 없으면 재귀 호출 종료.
if (boardCount === 0) {
return;
}

// start에서 mid까지 end를 거쳐 옮기는데
// 맨 밑바닥 원판은 옮기지 않는다.
helper(start, end, mid, boardCount - 1);

// 맨 밑바닥 원판을 옮긴다.
answer.push(`${start + 1} ${end + 1}`);

// mid에서 대기중인 N-1개의 원판을
// start를 거쳐
// end로 옮긴다.
helper(mid, start, end, boardCount - 1);
};

helper(start, mid, end, boardCount);

console.log(answer.length);
console.log(answer.join('\n'));
};