티스토리 뷰
https://www.acmicpc.net/problem/1941
1941번: 소문난 칠공주
총 25명의 여학생들로 이루어진 여학생반은 5×5의 정사각형 격자 형태로 자리가 배치되었고, 얼마 지나지 않아 이다솜과 임도연이라는 두 학생이 두각을 나타내며 다른 학생들을 휘어잡기 시작
www.acmicpc.net
class Node {
constructor(item) {
this.item = item;
this.next = null;
}
}
class Queue {
constructor() {
this.head = null;
this.tail = null;
this.length = 0;
}
push(item) {
const node = new Node(item);
if (this.head == null) {
this.head = node;
} else {
this.tail.next = node;
}
this.tail = node;
this.length += 1;
}
pop() {
const popItem = this.head;
this.head = this.head.next;
this.length -= 1;
return popItem.item;
}
}
const input = require('fs')
.readFileSync('./dev/stdin')
.toString()
.trim()
.split('\n')
.map((v) => v.trim().split(''));
const dx = [0, 0, -1, 1];
const dy = [1, -1, 0, 0];
let answer = 0;
let board = Array.from(Array(5), () => Array(5));
for (let i = 0; i < 5; i++) {
for (let j = 0; j < 5; j++) {
board[i][j] = `${i}${j}`;
}
}
const girls = board.flat();
for (let a = 0; a < girls.length; a++) {
for (let b = a + 1; b < girls.length; b++) {
for (let c = b + 1; c < girls.length; c++) {
for (let d = c + 1; d < girls.length; d++) {
for (let e = d + 1; e < girls.length; e++) {
for (let f = e + 1; f < girls.length; f++) {
for (let g = f + 1; g < girls.length; g++) {
let seven = [a, b, c, d, e, f, g].map((v) => girls[v]);
const isPossible =
seven
.map((v) => input[+v[0]][+v[1]])
.filter((v) => v == 'S').length >= 4;
if (!isPossible) continue;
const q = new Queue();
const last = seven.pop();
q.push([+last[0], +last[1]]);
while (q.length > 0) {
const [x, y] = q.pop();
for (let k = 0; k < 4; k++) {
const nx = x + dx[k];
const ny = y + dy[k];
const next = `${nx}${ny}`;
if (seven.includes(next)) {
seven = seven.filter((v) => v != next);
q.push([nx, ny]);
}
}
}
if (seven.length == 0) {
answer++;
}
}
}
}
}
}
}
}
console.log(answer);
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Node.js) 백준 17141번: 연구소 2 (0) | 2023.07.09 |
---|---|
Node.js) 백준 16987번: 계란으로 계란치기 (0) | 2023.07.09 |
Node.js) 백준 11559번: Puyo Puyo (0) | 2023.07.08 |
Node.js) 백준 17219번: 비밀번호 찾기 (0) | 2023.07.08 |
Node.js) 백준 2935번: 소음 (0) | 2023.07.08 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 다이나믹프로그래밍
- MySQL
- 투포인터
- 면접비
- 투포인터 연습
- MOD
- DB 생성
- create db
- 서버개발
- BFS
- 개발자면접
- 최소공통조상
- 동적프로그래밍
- 로드나인
- 롱베케이션
- 서버점검
- create databases;
- 그래프
- 다이나밍프로그래밍
- 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 |
글 보관함