kokoball의 devlog
article thumbnail
백준 1261 알고스팟 (node.js)
WEB/백준 문제 풀이 2024. 6. 29. 20:53

문제https://www.acmicpc.net/problem/1261  문제 해석이 문제는 지금까지와는 다르게 우선순위가 있는 길 찾기이다.최대한 벽을 부수지 않고 이동해야하기 때문에 queue에 추가할 때 벽이 없는 길을 unshift를 이용해 queue 앞에 추가해 주고벽이 있는 경우에는 기존과 같이 push를 이용해 queue 뒤에 추가하면 된다. 풀이const filePath = process.platform === "linux" ? "dev/stdin" : "../test.txt";const input = require("fs").readFileSync(filePath).toString().trim().split("\n");const solution = (input) => { const [n,..

article thumbnail
백준 2606 바이러스 (node.js)
WEB/백준 문제 풀이 2024. 6. 12. 01:34

문제https://www.acmicpc.net/problem/2606문제 해석이 문제는 BFS로 쉽게 풀 수 있다.다만, 그래프의 앞 뒤가 구분되지 않기 때문에 둘다 추가하는 방식으로 풀어야한다. 풀이const filePath = process.platform === "linux" ? "dev/stdin" : "../test.txt";const input = require("fs").readFileSync(filePath).toString().trim().split("\n");function solution(input) { const qty = Number(input.shift()); const pair = Number(input.shift()); const computers = input.map(..

article thumbnail
백준 3190번 뱀 (node.js)
WEB/백준 문제 풀이 2024. 5. 22. 00:03

문제https://www.acmicpc.net/problem/3190 문제 해석이 문제도 전체 배열에 뱀이 지나가는 부분과 뱀 길이, 그리고 각각의 방향을 신경 쓰면 풀 수 있는 문제이다. 문제의 조건에 따라 N, K, L 정수를 구한다음 전체 배열을 생성하고 사과가 있는 위치의 값을 1로 바꿔준다.그 후 무한 반복문을 통해 각각의 조건에 맞춰서 이동하면 된다.풀이const filePath = process.platform === "linux" ? "dev/stdin" : "../test.txt";const input = require("fs").readFileSync(filePath).toString().trim().split("\n");function solution(input) { const N ..

article thumbnail
백준 11536번 줄 세우기 (node.js)
WEB/백준 문제 풀이 2024. 5. 21. 19:13

문제https://www.acmicpc.net/problem/11536  문제 해석이 문제는 간단한 구현 문제이며, set 배열을 통해 중복을 방지하고 만약 크기가 1 이상일 겨우 NEITHER을 아닐 경우 각각의 값을 리턴하여 해결하였다. 풀이const filePath = process.platform === "linux" ? "dev/stdin" : "../test.txt";const input = require("fs").readFileSync(filePath).toString().trim().split("\n");function solution(input) { const N = Number(input.shift()); let index = input[0].charCodeAt(0); let t..

article thumbnail
백준 14504번 로봇 청소기 (node.js)
WEB/백준 문제 풀이 2024. 5. 20. 18:09

문제https://www.acmicpc.net/problem/14503  문제 해석이 문제는 구현 문제이며, 방문 체크를 위한 배열 visited와 각각의 방향 체크를 위한 dx, dy로 분리해서 해결하였다. 문제의 요구사항대로 먼저 현재 위치 청소 여부를 확인하고 청소했으면 -1로 값을 변경한 후 각각의 방향을 검사하여 기계의 진행을 설정해 주었다. 풀이const filePath = process.platform === "linux" ? "dev/stdin" : "../test.txt";const input = require("fs").readFileSync(filePath).toString().trim().split("\n");function solution(input) { const [n, m] ..

article thumbnail
백준 2578번 덩치 (node.js)
WEB/백준 문제 풀이 2024. 5. 18. 11:37

문제https://www.acmicpc.net/problem/7568  문제 해석이 문제는 전체 탐색인 브루트 포스 (brute force) 관련 문제이다.브루트 포스 방법은 해가 존재할 것으로 예상되는 모든 영역을 전체 탐색하는 방법이다. (순차 탐색, 깊이 우선 탐색 DFS, 너비 우선 탐색 BFS) (자세한 설명) 따라서 중첩 반복문을 이용해 현재 몸무게와 키를 비교해 있다면 인덱스를 1 씩 더해주면 된다.  풀이const filePath = process.platform === "linux" ? "dev/stdin" : "../test.txt";let input = require("fs") .readFileSync(filePath) .toString() .trim() .split("\n")..

article thumbnail
백준 2578번 빙고 (node.js)
WEB/백준 문제 풀이 2024. 5. 17. 16:44

문제https://www.acmicpc.net/problem/2578  문제 해석이 문제는 이중 반복문을 통해 각 원소가 체크 됐는지 확인하고, 그 순간에 빙고를 확인하면 되는 문제이다.가로 세로와 대각선 빙고 상황을 구분해서 확인하는 함수를 만들어 해결하였다. 풀이const filePath = process.platform === "linux" ? "dev/stdin" : "../test.txt";const input = require("fs").readFileSync(filePath).toString().trim().split("\n");function solution(input) { let board = []; let visited = Array.from({ length: 5 }, () => A..

article thumbnail
백준 2669번 직사각형 네개의 합집합의 면적 구하기 (node.js)
WEB/백준 문제 풀이 2024. 5. 15. 17:50

문제https://www.acmicpc.net/problem/2669 문제 해석이 문제는 지나간 거리를 구하는 문제처럼 평면의 각 점에 대한 존재 여부를 확인하는 방법으로 구현 가능하다. 각 직사각형의 좌표를 입력하는데 주의할 점은 꼭짓점 좌표를 포함하면 안 된다. 풀이const filePath = process.platform === "linux" ? "dev/stdin" : "../test.txt";const input = require("fs").readFileSync(filePath).toString().trim().split("\n");function solution(input) { const grid = Array.from({ length: 101 }, () => Array(101).fill..

728x90