From 9944dc6700964dba4ff12ba7e4acd60fcfbc208f Mon Sep 17 00:00:00 2001 From: LJH <049494@ewhain.net> Date: Tue, 19 Dec 2023 16:32:38 +0900 Subject: [PATCH] feat: 231219 --- "Doozuu/231219/boj_DFS\354\231\200BFS.js" | 54 +++++++++++++++++++ ...70\353\266\231\354\235\264\352\270\260.js" | 44 +++++++++++++++ ...60\353\234\250\353\246\254\352\270\260.js" | 28 ++++++++++ ...21\353\254\274\354\272\220\352\270\260.js" | 28 ++++++++++ ...74\353\263\264\354\204\244\354\271\230.js" | 53 ++++++++++++++++++ 5 files changed, 207 insertions(+) create mode 100644 "Doozuu/231219/boj_DFS\354\231\200BFS.js" create mode 100644 "Doozuu/231219/boj_\353\213\250\354\247\200\353\262\210\355\230\270\353\266\231\354\235\264\352\270\260.js" create mode 100644 "Doozuu/231219/boj_\355\222\215\354\204\240\355\204\260\353\234\250\353\246\254\352\270\260.js" create mode 100644 "Doozuu/231219/pro_\352\264\221\353\254\274\354\272\220\352\270\260.js" create mode 100644 "Doozuu/231219/pro_\352\270\260\353\221\245\352\263\274\353\263\264\354\204\244\354\271\230.js" diff --git "a/Doozuu/231219/boj_DFS\354\231\200BFS.js" "b/Doozuu/231219/boj_DFS\354\231\200BFS.js" new file mode 100644 index 0000000..a4dd81c --- /dev/null +++ "b/Doozuu/231219/boj_DFS\354\231\200BFS.js" @@ -0,0 +1,54 @@ +const fs = require('fs'); +const filePath = process.platform === 'linux' ? '/dev/stdin' : 'ex.txt'; +const input = fs.readFileSync(filePath).toString().trim().split('\n'); + +const [N, M, V] = input.shift().split(' ').map(Number); +const numbers = input.map((el) => el.split(' ').map(Number)); +const graph = Array.from({length: N + 1}, () => []); + +numbers.map(([from, to]) => { + graph[from].push(to); + graph[to].push(from); +}); + +graph.forEach((nodes) => nodes.sort((a, b) => a - b)); + +// DFS +function DFS(graph, startNode) { + const visited = []; + let needVisit = []; + + needVisit.push(startNode); + + while (needVisit.length !== 0) { + const node = needVisit.shift(); + if (!visited.includes(node)) { + visited.push(node); + needVisit = [...graph[node], ...needVisit]; + } + } + return visited; +} + +// BFS +function BFS(graph, startNode) { + const visited = []; + let needVisit = []; + + needVisit.push(startNode); + + while (needVisit.length !== 0) { + const node = needVisit.shift(); + if (!visited.includes(node)) { + visited.push(node); + needVisit = [...needVisit, ...graph[node]]; + } + } + return visited; +} + +const dfs = DFS(graph, V); +const bfs = BFS(graph, V); + +console.log(dfs.join(' ')); +console.log(bfs.join(' ')); diff --git "a/Doozuu/231219/boj_\353\213\250\354\247\200\353\262\210\355\230\270\353\266\231\354\235\264\352\270\260.js" "b/Doozuu/231219/boj_\353\213\250\354\247\200\353\262\210\355\230\270\353\266\231\354\235\264\352\270\260.js" new file mode 100644 index 0000000..3e2e9f2 --- /dev/null +++ "b/Doozuu/231219/boj_\353\213\250\354\247\200\353\262\210\355\230\270\353\266\231\354\235\264\352\270\260.js" @@ -0,0 +1,44 @@ +const fs = require('fs'); +const filePath = process.platform === 'linux' ? '/dev/stdin' : 'ex.txt'; +const input = fs.readFileSync(filePath).toString().trim().split('\n'); + +const N = Number(input.shift()); +const board = input.map((el) => el.split('').map(Number)); +const visited = Array.from({length: N}, () => Array(N).fill(false)); +const answer = []; +const move = [ + [0, 1], + [0, -1], + [1, 0], + [-1, 0], +]; +let count = 0; + +function DFS(i, j) { + if (i < 0 || j < 0 || i >= N || j >= N || visited[i][j] || !board[i][j]) { + return; + } + + count++; + visited[i][j] = true; + + for (const [dx, dy] of move) { + const newX = i + dx; + const newY = j + dy; + DFS(newX, newY); + } + + return count; +} + +for (let i = 0; i < N; i++) { + for (let j = 0; j < N; j++) { + if (board[i][j] && !visited[i][j]) { + answer.push(DFS(i, j)); + count = 0; + } + } +} + +console.log(answer.length); +console.log(answer.sort((a, b) => a - b).join('\n')); diff --git "a/Doozuu/231219/boj_\355\222\215\354\204\240\355\204\260\353\234\250\353\246\254\352\270\260.js" "b/Doozuu/231219/boj_\355\222\215\354\204\240\355\204\260\353\234\250\353\246\254\352\270\260.js" new file mode 100644 index 0000000..2c5e075 --- /dev/null +++ "b/Doozuu/231219/boj_\355\222\215\354\204\240\355\204\260\353\234\250\353\246\254\352\270\260.js" @@ -0,0 +1,28 @@ +// 메모리 초과 + +const fs = require('fs'); +const filePath = process.platform === 'linux' ? '/dev/stdin' : 'ex.txt'; +const input = fs.readFileSync(filePath).toString().trim().split('\n'); + +const N = Number(input[0]); +const arr = input[1].split(' ').map(Number); +let ballonNum = Array.from({length: N}, (_, i) => i + 1); +let resultArr = []; +let idx = 0; + +let K = arr.splice(idx, 1)[0]; +resultArr.push(ballonNum.splice(idx, 1)[0]); + +while (arr.length > 0) { + if (K > 0) { + idx = (idx + (K - 1)) % arr.length; + } else { + K = K * -1; + idx = arr.length - idx - 1; + idx = arr.length - ((idx + K) % arr.length) - 1; + } + K = arr.splice(idx, 1)[0]; + resultArr.push(ballonNum.splice(idx, 1)[0]); +} + +console.log(resultArr.join(' ')); diff --git "a/Doozuu/231219/pro_\352\264\221\353\254\274\354\272\220\352\270\260.js" "b/Doozuu/231219/pro_\352\264\221\353\254\274\354\272\220\352\270\260.js" new file mode 100644 index 0000000..e670837 --- /dev/null +++ "b/Doozuu/231219/pro_\352\264\221\353\254\274\354\272\220\352\270\260.js" @@ -0,0 +1,28 @@ +function solution(picks, minerals) { + var answer = 0; + let len = Math.ceil(minerals.length / 5); + let maxLen = picks.reduce((a, b) => a + b); + let arr = []; + if (maxLen === 0) return 0; // 곡괭이가 하나도 없는 경우 + minerals = minerals.splice(0, maxLen * 5); // 더이상 사용할 곡괭이가 없을 경우를 위해 + + for (let a = 0; a < len; a++) { + let obj = {d: 0, i: 0, s: 0}; + minerals.splice(0, 5).map((v) => obj[v[0]]++); // 광물 개수 카운트 + arr.push([ + obj.d * 1 + obj.i * 1 + obj.s * 1, // 곡괭이별 피로도 계산 + obj.d * 5 + obj.i * 1 + obj.s * 1, + obj.d * 25 + obj.i * 5 + obj.s * 1, + ]); + } + // 피로도가 큰 순서로 내림차순 정렬하여 다이아 -> 철 -> 돌 순서대로 곡괭이 사용 + arr + .sort((a, b) => b[2] - a[2]) + .map((v) => { + if (picks[0] > 0) return picks[0]--, (answer += v[0]); + if (picks[1] > 0) return picks[1]--, (answer += v[1]); + if (picks[2] > 0) return picks[2]--, (answer += v[2]); + }); + + return answer; +} diff --git "a/Doozuu/231219/pro_\352\270\260\353\221\245\352\263\274\353\263\264\354\204\244\354\271\230.js" "b/Doozuu/231219/pro_\352\270\260\353\221\245\352\263\274\353\263\264\354\204\244\354\271\230.js" new file mode 100644 index 0000000..5ee68b7 --- /dev/null +++ "b/Doozuu/231219/pro_\352\270\260\353\221\245\352\263\274\353\263\264\354\204\244\354\271\230.js" @@ -0,0 +1,53 @@ +// 통과 x + +function solution(n, build_frame) { + let answer = []; + + function isIncludes(target) { + return answer.some((arr) => JSON.stringify(arr) === JSON.stringify(target)); + } + + build_frame.forEach(([x, y, type, action]) => { + let isValid = false; + if (type === 0) { + // 1. 바닥 위 + if (y === 0) isValid = true; + // 2. 보의 한쪽 끝 위 + if (isIncludes([x - 1, y, 1]) || isIncludes([x + 1, y, 1])) isValid = true; + // 3. 다른 기둥 위 + if (isIncludes([x, y - 1, 0])) isValid = true; + } + if (type === 1) { + // 1. 한 쪽 기둥 위 + if (isIncludes([x, y - 1, 0]) || isIncludes([x + 1, y - 1, 0])) isValid = true; + // 2. 두 쪽 모두 다른 보와 연결 + if (isIncludes([x - 1, y, 1]) && isIncludes([x + 1, y, 1])) isValid = true; + } + + if (isValid) { + if (action === 0) { + if (isIncludes([x - 1, y, type]) && isIncludes([x + 1, y, type])) { + return; + } + const idx = answer.findIndex(([i, j, t]) => i === x && j === y && t === type); + if (idx > -1) answer.splice(idx, 1); + } + if (action === 1) { + answer.push([x, y, type]); + } + } + }); + + return answer.sort((a, b) => { + if (a[0] === b[0]) { + if (a[1] === b[1]) { + return a[2] - b[2]; + } + return a[1] - b[1]; + } + return a[0] - b[0]; + }); +} +// x, y, 구조물 종류(0 기둥, 1 보), 설치/삭제(0 삭제, 1 설치) +// 기둥 설치 : 바닥, 보의 한쪽 끝 위, 다른 기둥 위 +// 보 설치 : 한 쪽 기둥 위, 두 쪽 다른 보와 연결