일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 프로그래머스 레벨 2
- 쉬운 문제
- 수학
- ip
- TCP
- 레벨 1
- 문자열
- 타입 챌린지
- dfs
- HTTP
- HTTP 완벽 가이드
- dp
- Algorithm
- socket
- 가천대
- Node.js
- typescript
- javascript
- Nestjs
- 소켓
- 프로그래머스
- 타입스크립트
- 자바스크립트
- BFS
- Crawling
- 알고리즘
- 백준
- 그래프
- type challenge
- 크롤링
- Today
- Total
목록dfs (17)
kakasoo
// 프로그래머스 레벨2 점프와 순간 이동을 풀었습니다. const solution = (n) => { // const visited = new Array(n + 1).fill(0).map((el, i) => i); // const dfs = (cur) => { // for (let i = 1; 2 ** i * cur el == 1).length; } dfs로 시간 초과가 떠서 bfs로 고치고, 최적화를 위해서 별 짓을 다 했는데도 시간 초과는 사라지지 않았다. 혹시 그래프적인 방법 외에도 뭔가 있나 고민해봤는데, 2로 나눴을 때의 나머지가 1인 횟수가 아무래도 답인 거 같다. 그래서 2진수로 변환하여 구했다.
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let N = 0; const input = []; rl.on("line", (line) => { if (!N) { N = Number(line); } else { input.push(line); if (input.length === N - 1) { main(); } } }); const main = () => { const graph = []; const answer = []; for (let i = 1; i { const [from, to] = edge.split(" "); gr..
시간 초과를 해결했더니, 공간 복잡도가 높아지는 문제가 있었다. 일반적으로, dfs로 해서 해결될만한 문제 같은데, 35% 이상을 넘어가면 런타임 에러가 발생했다. ( 중간에 CannotFindModule은 자동완성 때문에 그러하다. ) 내 개인적인 생각으로는, 스택 영역이 고갈되었기 때문이다. 사실, StackSizeExceeded라고 써있으니 당연한 거 아닌가, 생각할 수 있겠지만, 그래도 생각해볼 부분이 나름 있다. 자바스크립트의 변수는 다른 언어들보다 좀 크다. 숫자의 경우의 8바이트, 기본적으로 모든 숫자가 double이기 때문이다. 그러니깐 잘 짜려고 노력해도 남들보다 변수를 2배 이상 가지고 있으니, 똑같은 함수여도 가끔씩 stack이 고갈된다. 따라서 정적인 영역 ( 데이터 영역 )으로 조..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const graph = []; let N, M; rl.on("line", (line) => { if (!N) { [N, M] = line.split(" ").map(Number); } else { const row = line.split(" ").map(Number); graph.push(row); if (graph.length === N) { rl.close(); } } }).on("close", () => { const visited = []; for (let i = 0; i ..
// 백준 1707번 이분 그래프를 풀었습니다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let count = 0; let input = []; rl.on("line", (line) => { if (!count) { count = Number(line); } else { input.push(line); if (input.length == Number(input[0].split(" ")[1]) + 1) { main(); input = []; } } }); const main = () => { const graph = []; ..
kscodebase.tistory.com/394 이전 문제에 JavaScript에 대한 단점들을 조금 나열했는데, 나름대로 깔끔하게 고쳐보고자 이번에는 중첩된 함수 구조를 사용했다. // 백준 11724번 연결요소의 게수를 풀었습니다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const input = []; let N = 0; let M = 0; rl.on("line", (line) => { if (!N) { [N, M] = line.split(" ").map(Number); } else { input.push(line);..
// 백준 1260번 DFS와 BFS를 풀었습니다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const input = []; let n = 0; let m = 0; let start = 0; rl.on("line", (line) => { if (!n) { [n, m, start] = line.split(" ").map(Number); } else { input.push(line); if (input.length === m) { main(); process.exit(); } } }); const dfs = (start) =>..
// 백준 13023번 ABCDE를 풀었습니다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const input = []; let N = 0; let M = 0; rl.on("line", (line) => { if (!N) { [N, M] = line.split(" ").map(Number); } else { input.push(line); if (input.length === M) { main(); process.exit(); } } }); let visited; let arr; let answer = []; /** * *..
C언어를 다룰 때 가장 힘든 것이 동적할당이었다. 동적할당을 처음 배울 당시, 나는 프로그래밍을 마치고 동적할당을 해제하지 않으면, 컴퓨터의 자원을 영영 잃어버리는 것이 아닐지, 그 부분에 대해서 두려움을 가졌다. 당연히 지금은 운영체제가 그런 부분을 자동적으로 처리해준다는 것을 알고 있다. 하지만 그 사실을 몰랐던 나는, 동적할당을 의사가 환자 다루듯 신중하게 해야 했다. 도달 가능성 Mark-and-Sweep 알고리즘이 있다. 이는 말하자면 DFS, BFS와 유사하게, 도달가능한 모든 영역을 탐색하는 알고리즘이다. 나중에 다른 포스팅에서 말하겠지만, JavaScript는 다양한 Enviorment를 Context로 가진다. Mark-and-Sweep 알고리즘은 이 환경 중 맨 처음에 위치할 전역 환경..
여기에 작성된 코드는 절대로 좋은 코드가 아니니, 참고하지 말 것! 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 #include #include using namespace std; /* 1232123 이라는 숫자가 있다고 할 때, 기준점을 하나씩 옮겨가며, 양측의 숫자들이 동일..
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 #include #include #include using namespace std; char arr[15]; bool visited[15]; int l, c; int moum; int jaum; vector str; void dfs(int cur, int start) { if (cur == l && moum >= 1 && jaum >= 2) { for (int i = 0; i
알고리즘에 대해 알고리즘을 배우기 전에 대부분의 사람들이 궁금한 것이, 수학적인 능력의 유무가 알고리즘을 배우는 데에 필수적인지 일 것이다. 나도 어렴풋이 그런 걸 느끼기도 했고, 경험해가며 굳이 필요없다는 것을 느꼈다. 인공지능을 한다거나, 아니면 그래픽스를 할 게 아니라면 필요없다는 것을 이해할 수 있었다. 비록 내가 인공지능이나 그래픽스를 해본 것은 아니지만, 수식을 쓰는가 안 쓰는가, 그런 도구적인 쓰임과 자신이 사용하는 공식들에 대한 이해 없이 그저 수학적 사고력만으로 풀 수 있는 문제들 선이 내게 필요한 cut line 이었기 때문이다. 그 이상으로 가려면 아직 시간도 많고, 필요할 때 배워도 문제 없겠다고 싶었다. (Q. 나는 하루에 8시간 정도 code를 짜고 있는데, 필요할 때 배워도 문..