Notice
Recent Posts
Recent Comments
Link
ยซ   2024/09   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
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
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Lennon FE

[๋ฐฑ์ค€ 2775๋ฒˆ] ๋ถ€๋…€ํšŒ์žฅ์ด ๋ ํ…Œ์•ผ - ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(nodejs) ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm/Baekjoon

[๋ฐฑ์ค€ 2775๋ฒˆ] ๋ถ€๋…€ํšŒ์žฅ์ด ๋ ํ…Œ์•ผ - ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(nodejs)

Lennon 2022. 1. 17. 06:25
728x90
๋ฐ˜์‘ํ˜•

https://www.acmicpc.net/problem/2775

 

2775๋ฒˆ: ๋ถ€๋…€ํšŒ์žฅ์ด ๋ ํ…Œ์•ผ

์ฒซ ๋ฒˆ์งธ ์ค„์— Test case์˜ ์ˆ˜ T๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ฐ๊ฐ์˜ ์ผ€์ด์Šค๋งˆ๋‹ค ์ž…๋ ฅ์œผ๋กœ ์ฒซ ๋ฒˆ์งธ ์ค„์— ์ •์ˆ˜ k, ๋‘ ๋ฒˆ์งธ ์ค„์— ์ •์ˆ˜ n์ด ์ฃผ์–ด์ง„๋‹ค

www.acmicpc.net

 

const fs = require('fs');
let input = fs
  .readFileSync('dev/stdin', 'utf-8')
  .toString()
  .trim()
  .split('\n')
  .map((v) => +v);

input.shift();

const value = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]];
let idx = 0;

while (value.length !== 15) {
  let arr = [];
  let count = 0;
  for (let i = 0; i < 14; i++) {
    count += value[idx][i];
    arr.push(count);
  }

  value.push(arr);
  idx++;
}

while (input.length !== 0) {
  const first = input.shift();
  const second = input.shift();

  console.log(value[first][second - 1]);
}

์ฒซ ๋ฒˆ์งธ ์™€์ผ๋ฌธ์—์„œ 15์ธต๊นŒ์ง€ ๊ฐ’๋“ค์„ ๋ชจ๋‘ value๊ฐ’์— ์ €์žฅํ•œ๋‹ค.

 

์ž…๋ ฅ๊ฐ’์ด  2 ๊ฒฝ์šฐ๋ฅผ ์ž…๋ ฅํ• ๊ฑฐ๋ผ๊ณ  ์ฒซ ๋ฒˆ์งธ ์ž…๋ ฅ์„ ํ•˜๊ณ  (shift๋กœ ์ œ๊ฑฐ)

๋‘ ๊ฐœ์”ฉ ๋ฌถ์—ฌ ์žˆ์œผ๋ฏ€๋กœ ๋งˆ์ง€๋ง‰ while๋ฌธ์— shift๋ฅผ ํ•˜๋ฉด์„œ ๊ธธ์ด๊ฐ€ 0์ด ๋  ๋•Œ๊นŒ์ง€ ๋ฐฐ์—ด์—์„œ ์ถœ๋ ฅ์„ ํ–ˆ๋‹ค.

728x90
๋ฐ˜์‘ํ˜•
Comments