백준[JS] > 11501번 주식
·
🔒Algorithm
링크https://www.acmicpc.net/problem/11501 문제풀이1. 메모리 초과로 실패한 코드-> 굳이 새로운 배열(refArr) 을 만들고 2번의 순회를 할 필요가 없었다.const fs = require("fs");const input = fs .readFileSync("/dev/stdin") .toString() .split("\n") .map((str) => { return str.split(" ").map((n) => Number(n)); }); for (let i = 1; i 1) { let benefit = 0; let prices = input[i]; let max = 0; le..
백준[JS] > 11000번 강의실 배정
·
🔒Algorithm
문제링크https://www.acmicpc.net/problem/11000 제출코드 일단 수업들을 시작시간이 빠른순으로 정렬하고 시작시간이 같으면 끝나는 시간이 빠른시간 순으로 정렬하였다.그리고 정렬한 수업들을 순회하면서 최소 힙과 비교하면서(힙을 안쓰고 정렬을 이용하면 연산횟수가 기하급수적으로 많아서 시간초과가 발생한다.) 비어있는 강의실이 없는 경우 힙에 새롭게 추가하였다. 여기서 추가할 때 수업의 끝나는 시간만 힙에 추가했다. ( 우리가 필요한 정보는 수업이 끝나는 시간이기 때문이다. )마지막에 힙의 사이즈를 통해 몇개의 강의실이 쓰였는 지 알 수 있다.참고) 자바스크립트에서는 힙 자료구조를 직접 구현해야 한다.class MinHeap { constructor() { this.he..
백준[JS] > 1092번 배
·
🔒Algorithm
문제 링크https://www.acmicpc.net/problem/1092 해설큰 문제 없이 해결 가능했다. const fs = require("fs");const input = fs.readFileSync("/dev/stdin").toString().split("\n");const craneCnt = Number(input[0]);const craneArr = input[1].split(" ").map((n) => Number(n));craneArr.sort((a, b) => b - a);const boxCnt = Number(input[2]);const boxArr = input[3].split(" ").map((n) => Number(n));boxArr.sort((a, b) => b - a);if ..
백준[JS] > 1058번 친구
·
🔒Algorithm
문제 링크https://www.acmicpc.net/problem/1058 해설큰 문제없이 풀 수 있었다. 중복을 따로 처리하기 귀찮아 set을 이용하였다. const fs = require("fs");const input = fs.readFileSync("/dev/stdin").toString().split("\n");const cnt = Number(input[0])// [N,Y,N,N,N]// [N,Y,N,N,N]// [N,Y,N,Y,N]// [N,N,Y,N,Y]// [N,n,N,Y,N]let map = [];for (let i = 1; i { for (let z = 0; z
백준[JS] > 1051번 숫자 정사각형
·
🔒Algorithm
🔥문제링크https://www.acmicpc.net/submit/1051/85874949  🔥풀이만들 수 있는 가장 큰 정사각형 부터 단순 반복문을 돌리면 해결 할 수 있다.!const fs = require("fs");const input = fs.readFileSync("/dev/stdin").toString().split("\n");const [r,c] = input[0].split(" ").map((n)=>Number(n))let map =[] // [[1,0,0],[2,0,0]]for(let i=1; iNumber(n)) map.push(arr)}let least = Math.min(r,c)let answer = 1for(let i=least; i>=2; --i){ for(let ..
백준[JS] > 1021번 회전하는 큐
·
🔒Algorithm
🔥문제링크https://www.acmicpc.net/problem/1021  🔥풀이처음에는 연산횟수를 고려해서 arr의 배열원소의 shift를 하지않고 푸는 줄 알았는데 굳이 그러지 않고 그냥 shift와 push를 이용하면 쉽게 풀수 있다.const fs = require("fs");const input = fs.readFileSync("/dev/stdin").toString().split("\n");const arr = input[1].split(" ").map((t) => Number(t));const [n, m] = input[0].split(" ").map((t)=>Number(t));let dic = [];for (let i = 1; i { dic.shift();};const f2 ..
백준[JS] > 1074번 Z
·
🔒Algorithm
🔥문제링크https://www.acmicpc.net/problem/1074 🔥풀이일단 2**N X 2**N 이루어진 배열에서 2**N-1 * 2**N-1 으로 4개의 영역 중 어떤 영역에 속해있는지 판별하면서 재귀적으로 스코프를 계속해서 좁혀 나갔다. 좁혀나가면서 Skip한 영역에 속해있는 개수를 지속해서 answer에 더하였다.// 5분const fs = require("fs");const input = fs.readFileSync("/dev/stdin").toString();//.split("\n");let [N, r, c] = input.split(" ").map((n) => Number(n));if(N===1){ if(r==0&&c==0){ console.log(0) }..