티스토리 뷰
https://www.acmicpc.net/problem/1654
1654번: 랜선 자르기
첫째 줄에는 오영식이 이미 가지고 있는 랜선의 개수 K, 그리고 필요한 랜선의 개수 N이 입력된다. K는 1이상 10,000이하의 정수이고, N은 1이상 1,000,000이하의 정수이다. 그리고 항상 K ≦ N 이다. 그
www.acmicpc.net
이분탐색에서 while문 조건식이 min<max 로 해야되는지 min<=max로 해야되는지 잘 모르겠다. 😔
const fs = require('fs');
const [A,...B] = fs.readFileSync("./dev/stdin").toString().trim().split("\n");
const [_,N] = A.split(' ');
const cable =B.map(v=>+v);
let min = 0;
let max = Math.max(...cable);
let answer = 0;
while(min<=max){
let mid = Math.floor((min+max)/2);
let cnt =0;
cable.forEach(c=>{
cnt+=Math.floor(c/mid);
})
if(cnt>=N){
if(mid>answer) answer=mid;
min=mid+1;
}else{
max=mid-1
}
}
console.log(answer)
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Node.js)백준 2110번 : 공유기 설치 (0) | 2021.09.15 |
---|---|
Node.js)백준 2805번 : 나무 자르기 (1) | 2021.09.14 |
Node.js) 백준 10816번 : 숫자 카드 2 (0) | 2021.09.14 |
Node.js) 백준 1920번 : 수 찾기 (0) | 2021.09.14 |
Node.js) 백준 1780번 : 종이의 개수 (0) | 2021.09.14 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- create databases;
- create db
- 최소공통조상
- 은둔청년체험
- 개발자면접
- 면접비
- 투포인터 연습
- 투포인터
- 로드나인
- MySQL
- 다이나믹프로그래밍
- 롱베케이션
- MOD
- DB 생성
- 다이나밍프로그래밍
- 면접질문
- node.js
- 그래프
- 동적프로그래밍
- 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 |
글 보관함