Link
Notice
HIT해
[JS 백준] 1654.랜선 자르기 본문
728x90
https://www.acmicpc.net/problem/1654
1654번: 랜선 자르기
첫째 줄에는 오영식이 이미 가지고 있는 랜선의 개수 K, 그리고 필요한 랜선의 개수 N이 입력된다. K는 1이상 10,000이하의 정수이고, N은 1이상 1,000,000이하의 정수이다. 그리고 항상 K ≦ N 이다. 그
www.acmicpc.net
const filePath = process.platform === 'linux' ? '/dev/stdin' : 'input.txt';
let [N,...input] = require("fs")
.readFileSync(filePath)
.toString()
.trim().split('\n');
N = N.split(' ')[1]; // 원하는 랜선 갯수
input = input.map(r=> +r.replace('\r','')).sort((a,b) => a-b);
let max = input[input.length-1];
let min = 1;
while(min<= max){
let mid = Math.floor((max+min)/2);
let count = 0;
for(let i = 0; i < input.length; i++){
count += Math.floor(input[i]/mid);
}
if (count >= N) {
min = mid + 1;
} else {
max = mid - 1;
}
}
console.log(max);
'Vue > JavaScript 알고리즘' 카테고리의 다른 글
[JS 백준] 17298.오큰수 (0) | 2024.01.18 |
---|---|
[JS 프로그래머스] 큰수구하기 (0) | 2024.01.18 |
[JS 백준] 2630.색종이 만들기 (0) | 2024.01.14 |
[JS 백준] 1780.종이의 개수 (0) | 2024.01.14 |
[JS 프로그래머스] 2024 KAKAO_가장 많이 받은 선물 (0) | 2024.01.14 |