티스토리 뷰
https://www.acmicpc.net/problem/14499
14499번: 주사위 굴리기
첫째 줄에 지도의 세로 크기 N, 가로 크기 M (1 ≤ N, M ≤ 20), 주사위를 놓은 곳의 좌표 x, y(0 ≤ x ≤ N-1, 0 ≤ y ≤ M-1), 그리고 명령의 개수 K (1 ≤ K ≤ 1,000)가 주어진다. 둘째 줄부터 N개의 줄에 지
www.acmicpc.net
그냥 구현문제
const fs = require('fs');
const input = fs.readFileSync('./dev/stdin').toString().trim().split('\n');
const [N, M, X, Y, K] = input.shift().split(' ').map(Number);
const COMMANDS = input.pop().split(' ').map(Number);
let MAP = input.map((v) => v.split(' ').map(Number));
// 2
// 4 1 3
// 5
// 6
// 1 동
// 2 서
// 3 북
// 4 남
let x = X;
let y = Y;
let dice = [null, 0, 0, 0, 0, 0, 0];
let top = 6;
let bottom = 1;
let front = 5;
let back = 2;
let left = 4;
let right = 3;
const answer = [];
function move(dir) {
const originTop = top;
const originBottom = bottom;
const originFront = front;
const originBack = back;
const originLeft = left;
const originRight = right;
switch (dir) {
case 1: //동쪽
{
top = originLeft;
bottom = originRight;
left = originBottom;
right = originTop;
}
break;
case 2: //서쪽
{
top = originRight;
bottom = originLeft;
left = originTop;
right = originBottom;
}
break;
case 3: //북쪽
{
top = originFront;
bottom = originBack;
front = originBottom;
back = originTop;
}
break;
case 4: //남쪽
{
top = originBack;
bottom = originFront;
front = originTop;
back = originBottom;
}
break;
}
}
const dx = [0, 0, 0, -1, 1];
const dy = [0, 1, -1, 0, 0];
for (let i = 0; i < COMMANDS.length; i++) {
const cmd = COMMANDS[i];
const nx = x + dx[cmd];
const ny = y + dy[cmd];
if (nx < 0 || nx >= N || ny < 0 || ny >= M) {
continue;
} else {
x = nx;
y = ny;
}
move(cmd);
const now = MAP[x][y];
if (now === 0) {
MAP[x][y] = dice[bottom];
} else {
dice[bottom] = MAP[x][y];
MAP[x][y] = 0;
}
answer.push(dice[top]);
}
console.log(answer.join('\n'));
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Node.js)백준 14503번: 로봇청소기 (0) | 2023.06.11 |
---|---|
Node.js)백준 13458번: 시험감독 (0) | 2023.06.11 |
Node.js)백준 9019번: DSLR (0) | 2023.06.06 |
Node.js)백준 2903번: 중앙 이동 알고리즘 (0) | 2023.06.06 |
Node.js)백준 2720번: 세탁소 사장 동혁 (0) | 2023.06.06 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 은둔청년체험
- 동적프로그래밍
- 최소공통조상
- 개발자면접
- create databases;
- 투포인터
- 다이나믹프로그래밍
- MySQL
- DB 생성
- 롱베케이션
- 투포인터 연습
- MOD
- 그래프
- 다이나밍프로그래밍
- create db
- 서버점검
- 서버개발
- node.js
- 면접질문
- KMP
- BFS
- 로드나인
- 면접비
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함