[BOJ] 5427: 불 / JS
2022. 10. 9. 22:10
알고리즘
문제: https://www.acmicpc.net/problem/5427 const input = require('fs').readFileSync('/dev/stdin').toString().trim().split('\n'); const n = Number(input.shift()); const dx = [-1, 1, 0, 0]; const dy = [0, 0, -1, 1]; let visit; let h, w; class Node { constructor(data, next = null) { this.data = data; this.next = next; } } class Queue { constructor() { this.head = new Node([]); this.tail = this.head; ..
[BOJ] 7569: 토마토 / JS
2022. 10. 8. 19:19
알고리즘
문제: https://www.acmicpc.net/problem/7569 const input = require('fs').readFileSync('/dev/stdin').toString().trim().split('\n'); const [m, n, h] = input.shift().split(' ').map(Number); const map = []; let temp = []; for (let i = 0; i < h; i++) { for (let j = 0; j < n; j++) temp.push(...input.shift().split(' ').map(Number)); map.push(temp); temp = []; } const dh = [1, -1, 0, 0, 0, 0]; const dx = [0..
[BOJ] 10026: 적록색약 / JS
2022. 10. 8. 02:08
알고리즘
문제: https://www.acmicpc.net/problem/10026 const [n, ...input] = require('fs') .readFileSync('./input.txt') .toString() .trim() .split('\n'); const map = input.map((x) => x.trim().split('')); const visit = new Array(n); for (let i = 0; i 0); const dx = [0, 0, 1, -1]; const dy = [1, -1, 0, 0]; function isRange(x, y) { return x >= 0 && x < n && y..
[BOJ] 7562: 나이트의 이동 / JS
2022. 10. 7. 22:52
알고리즘
문제: https://www.acmicpc.net/problem/7562 const [t, ...input] = require('fs') .readFileSync('./input.txt') .toString() .trim() .split('\n'); const dx = [-2, -2, 2, 2, -1, 1, -1, 1]; const dy = [-1, 1, -1, 1, 2, 2, -2, -2]; let l; let map; function mapping() { map = new Array(l); for (let i = 0; i 0); } function isVisit(x, y) { return map[x][y]; }..
[BOJ] 2178: 미로 탐색 / JS
2022. 10. 7. 03:02
알고리즘
문제: https://www.acmicpc.net/problem/2178 const [nm, ...input] = require('fs').readFileSync('/dev/stdin').toString().trim().split('\n'); const [n, m] = nm.split(' ').map(Number); const maze = input.map((s) => s.trim().split('').map(Number)); const visit = new Array(n); for (let i = 0; i 0); const dx = [0, 0, -1, 1]; const dy = [1, -1, 0, 0]; fu..
[BOJ] 1926: 그림 / JS
2022. 10. 7. 02:20
알고리즘
문제: https://www.acmicpc.net/problem/1926 const [nm, ...input] = require('fs').readFileSync('/dev/stdin').toString().trim().split('\n'); const [n, m] = nm.split(' ').map(Number); const picture = input.map((s) => s.split(' ').map(Number)); function isRange(x, y) { return x >= 0 && x = 0 && y < m; } const dx = [0, 1, 0, -1]; const dy = [1, 0, -1, 0]; function bfs(i, j) { let area = 0; pic..
[BOJ] 11003: 최솟값 찾기
2022. 10. 3. 02:24
알고리즘
문제: https://www.acmicpc.net/problem/11003 #include using namespace std; deque dq; int n, l, num; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> l; for (int i = 0; i > num; if (!dq.empty() && dq.front().second + l == i) dq.pop_front(); while (!dq.empty() && dq.back().first >= num) dq.pop_back(); dq.push_back({num, i}); cout 최솟값을 덱에 저장하기 위함이며 큰 값들은 이미 최솟값의 의미를 잃었기 때..
[BOJ] 2493: 탑
2022. 10. 2. 19:33
알고리즘
문제: https://www.acmicpc.net/problem/2493 : 처음 작성한 코드 #include using namespace std; stack tower; vector result; int n, k; int pos, max_k; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i > k; if (!tower.empty()) { if (tower.top() > k) pos = tower.size(); else { if (k > max_k) { max_k = k; pos = 0; } } } tower.push(k); result.push_back(pos); } for (int..
[BOJ] 2504: 괄호의 값
2022. 10. 1. 22:45
알고리즘
문제: https://www.acmicpc.net/problem/2504 #include using namespace std; string str; stack st; int result, num = 1, valid = 1; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> str; for (int i = 0; i < str.length(); i++) { if (str[i] == '(') { num *= 2; st.push(str[i]); } else if (str[i] == '[') { num *= 3; st.push(str[i]); } else if (str[i] == ')') { if (st.empty() || st.top() != '(') { cout