일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 소켓
- 레벨 1
- dfs
- TCP
- 크롤링
- 수학
- Nestjs
- HTTP
- 프로그래머스 레벨 2
- Node.js
- type challenge
- Crawling
- 가천대
- BFS
- javascript
- 타입스크립트
- 백준
- ip
- dp
- socket
- 쉬운 문제
- 그래프
- Algorithm
- 자바스크립트
- typescript
- 문자열
- 타입 챌린지
- 프로그래머스
- 알고리즘
- HTTP 완벽 가이드
- Today
- Total
목록프로그래밍 (478)
kakasoo
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on("line", (line) => { main(Number(line)); rl.close(); }).on("close", () => { process.exit(); }); /** * * @param {number} line */ const main = (line) => { const DP = new Array(line + 1).fill(0); DP[2] = 3; for (let i = 4; i
부분 수열 문제랑 똑같은데, 연속이라는 점 때문에 2중 포문을 만들 필요가 없었다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let count = 0; rl.on("line", (line) => { if (!count) { count = Number(line); } else { main(line); rl.close(); } }).on("close", () => { process.exit(); }); /** * * @param {string} line */ const main = (line) => { const numbers..
이전 부분 수열 문제들처럼 풀되 조건만 바꿔주면 된다. 그런데 나는 틀렸었는데, 그 이유는 DP[i]의 값을 1로 초기화했기 때문이다. 이전 문제들은 개수를 세는 것이기 때문에 전부 1로 시작했겠지만, 이건 합산하는 것이기 때문에 각 DP[i]는 자기 차례의 숫자가 초깃값으로 저장되어야 한다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.output, }); let count = 0; rl.on("line", (line) => { if (!count) { count = Number(line); } else { main(line); rl.close(..
이전 문제는 결국 다른 사람의 코드를 참고했지만, 이 문제를 풀 때는 어제의 기억으로 그냥 풀 수 있었다. 사실 어제 문제랑 똑같다. 다른 점이 있다면 감소한다는 부분인데, 자바스크립트에서는 reverse라는 내장 함수가 있기 때문에 그냥 거꾸로 돌린 후에 똑같이 풀어주면 된다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.output, }); let count = 0; rl.on("line", (line) => { if (!count) { count = Number(line); } else { main(line); rl.close(); } })...
나는 이걸 틀려서, 결국 다른 사람의 코드를 참고했었다. 유명한 알고리즘이라 별도의 이름도 있다고 한다. LIS 라고 하는데, 말 그대로 Longest Increase Sequence? 뭐 그런 이름이었던 거 같다. 나는 이걸 짜기 위해서 n이 증가함에 따라 이전에 가능했던 수열에 새 값을 붙인 경우, 붙이지 않은 경우를 탐색했는데, 메모리 초과가 심각해서 풀 수가 없었다. DP는 DP 방법 말고는 답이 없는 듯 하다. 다음 문제가 가장 긴 감소하는 부분 수열인데,코드를 전혀 보지 않고 풀어보도록 하자. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process..
처음에는 대괄호, 소괄호를 따로 따로 배열을 만들어서 관리해 주었는데, 예외가 있었다. [(]) 형태로 들어올 때 제대로 동작하지 않았다. 그래서 배열을 하나로 합쳐줬더니 해결되었다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on("line", (line) => { if (line === ".") { rl.close(); } main(line); }).on("close", () => { process.exit(); }); /** * * @param {string} line */ const main = (line) =>..
부분 문자열, 부분 수열과 같다고 생각하면 되겠다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let count = 0; const input = []; rl.on("line", (line) => { if (!count) { count = Number(line); } else { input.push(line); if (input.length === count) { main(line); rl.close(); } } }).on("close", () => { process.exit(); }); const factorial = (n..
그렇게 어려운 문제는 아니었다. 그냥 마이너스를 할 때, 최대한 크게 마이너스를 해주면 된다. 그래서 마이너스가 나오면 마이너스 뒤로 있는 모든 플러스를 우선시해줘서 빼야할 값을 크게 바꿔주면 된다. 그래서 -를 기준으로 문자열을 split 해주고, 각 요소들을 전부 더 해준다. 예를 들어 43 - 43 + 45 - 45가 라는 문자열이 있으면 ( 띄어쓰기는 원래 없어야 한다. ) 43,48,45 라는 숫자 배열로 바꿔주고, 앞에서부터 차례대로 빼주면 된다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on("line",..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let count = 0; const input = [0]; rl.on("line", (line) => { if (!count) { count = Number(line); } else { input.push(Number(line)); if (input.length === count + 1) { main(); rl.close(); } } }).on("close", () => { process.exit(); }); const main = () => { const DP = new Arra..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let COUNT; let MAX_WEIGHT; let weights = [0]; let values = [0]; rl.on("line", (line) => { const arr = line.split(" ").map(Number); if (!COUNT && !MAX_WEIGHT) { COUNT = arr[0]; MAX_WEIGHT = arr[1]; } else { weights.push(arr[0]); values.push(arr[1]); if (weights.length > CO..
결코 신나지 않았다. 이게 Cpp였다면 솔직히 10분 안에 풀 자신도 있었다. 오류가 발생했다면 아마 다음과 같을 것이다. 배열에 string과 number를 혼용해서 쓰고 있지 않은가? 배열의 사이즈를 적절하게 하지 않아서 메모리가 초과되지 않았는가? 그냥 통째로 문자열로 다루려고 하지 않았는가? 예컨대, "111"를 키 값으로 저장한다던가... 이렇게 하면 문제가 발생한다. 다른 수, 예컨대 "1111"는 "1"과 "1"과 "11"의 조합인지, 아니면 11이 처음이나 중간에 나오는지 어떻게 구별하는가? 메모리가 꼬인다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, outp..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on("line", (line) => { main(line); rl.close(); }).on("close", () => { process.exit(); }); const dfs = (cur, max, value) => { if (cur === max) { console.log(value); process.exit(); } if (cur * 2