dolog

2024.02.29 탐욕(Greedy) 알고리즘 Part 3 본문

알고리즘

2024.02.29 탐욕(Greedy) 알고리즘 Part 3

dokite 2024. 2. 29. 15:18
// 백준 11509번 풍선 맞추기
// 어떤 예제에서 아래 풀이가 틀렸을까?

let fs = require('fs');
let input = fs.readFileSync('/dev/stdin').toString().split('\n');

let balloons = Number(input[0]);
let hegiht = input[1].split(" ").map(Number);

let arrow = 1;

for(let i = 0 ; i < balloons - 1 ; i++) {
   if(height[i] - 1 === height[i + 1]) {
       continue;
   } else {
       arrow++;
   } 
}

console.log(arrow);

 

1. BigInt

* Number 원시 값이 안정적으로 나타낼 수 있는 2^53 - 1(= 9007199254740991) 보다 큰 정수를 표현할 수 있는 내장 객체

* 정수 리터럴 뒤에 n을 붙이거나 (= 10n) 생성자 함수 BigInt()를 호출하여 생성할 수 있다.

* Math 객체의 메서드와 함께 사용할 수 없다.

* 타입은 'bigint' 이다.

const bigIntTestA = 9007199254740991n;
// 9007199254740991n
const bigIntTestB = BigInt(9007199254740991);
// 9007199254740991n
const bigIntTestC = BigInt("9007199254740991");
// 9007199254740991n

typeof bigIntTestA;
// 'bigint'

typeof bigIntTestA === typeof bigIntTestB && typeof bigIntTestA === typeof bigIntTestC;
// true

const bigNumber1 = BigInt(1000000000);
const bigNumber2 = 1000000000n;

console.log(bigNumber1 === bigNumber2); 
// true

 

참고

 

1. https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/BigInt