티스토리 뷰
https://www.acmicpc.net/problem/29733
29733번: 3차원 지뢰찾기
첫 번째 줄에는 세로, 가로, 높이를 나타내는 세 개의 정수 $R$, $C$, $H$가 공백으로 구분되어 주어진다. $(1 \le R, C, H \le 100)$ 두 번째 줄부터 큐브의 가장 밑에 있는 층부터 가장 위에 있는 층까지
www.acmicpc.net
const [RCH, ..._mine] = require('fs')
.readFileSync('./dev/stdin')
.toString()
.trim()
.split('\n')
.map((v) => v.trim());
const [R, C, H] = RCH.split(' ').map(Number);
const mine = Array.from(Array(H), () => Array());
const answer = Array.from(Array(H), () => Array.from(Array(R), () => Array(C).fill(0)));
let index = 0;
for (let i = 0; i < H; i++) {
for (let j = 0; j < R; j++) {
mine[i].push(_mine[index].split(''));
index++;
}
}
const dh = [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1];
const dr = [1, 1, 1, 0, 0, 0, -1, -1, -1, 1, 1, 1, 0, 0, -1, -1, -1, 1, 1, 1, 0, 0, 0, -1, -1, -1];
const dc = [1, 0, -1, 1, 0, -1, 1, 0, -1, 1, 0, -1, 1, -1, 1, 0, -1, 1, 0, -1, 1, 0, -1, 1, 0, -1];
for (let h = 0; h < H; h++) {
for (let r = 0; r < R; r++) {
for (let c = 0; c < C; c++) {
if (mine[h][r][c] == '*') {
answer[h][r][c] = '*';
continue;
}
for (let k = 0; k < 26; k++) {
const nh = h + dh[k];
const nr = r + dr[k];
const nc = c + dc[k];
if (nh < 0 || nh >= H) continue;
if (nr < 0 || nr >= R) continue;
if (nc < 0 || nc >= C) continue;
if (mine[nh][nr][nc] == '*') {
answer[h][r][c]++;
answer[h][r][c] %= 10;
}
}
}
}
}
console.log(answer.map((v) => v.map((y) => y.join('')).join('\n')).join('\n'));
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Node.js) 백준 29718번: 줄줄이 박수 (0) | 2023.09.11 |
---|---|
Node.js) 백준 29717번: 슬라임 잡고 레벨 업! (0) | 2023.09.11 |
Node.js) 백준 29723번: 브실이의 입시전략 (0) | 2023.09.11 |
Node.js) 백준 29732번: Rick-Roll Virus (0) | 2023.09.11 |
Node.js) 백준 29699번: Welcome to SMUPC! (0) | 2023.09.11 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 투포인터 연습
- 은둔청년체험
- DB 생성
- MOD
- MySQL
- 다이나믹프로그래밍
- 면접질문
- 그래프
- 로드나인
- create databases;
- create db
- 개발자면접
- BFS
- 롱베케이션
- 투포인터
- 다이나밍프로그래밍
- 최소공통조상
- 서버개발
- 면접비
- 서버점검
- 동적프로그래밍
- node.js
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함