티스토리 뷰
https://www.acmicpc.net/problem/10815
const fs = require('fs');
const input = fs.readFileSync("./dev/stdin").toString().trim().split("\n").map(v=>v.split(' ').map(x=>+x));
const own = input[1].sort((a,b)=>{return a-b});
const check = input[3];
const answer = [];
check.forEach(v=>{
answer.push(binarySearch(own,v))
})
console.log(answer.join(' '))
function binarySearch(arr,target){
let left = 0;
let right = arr.length-1;
while(left<=right){
const mid = Math.floor((left+right)/2);
if(arr[mid]==target){
return 1;
}else if(arr[mid]<target){
left = mid+1;
}else{
right = mid-1;
}
}
return 0;
}
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Node.js) 백준 1072번: 게임 (0) | 2021.12.14 |
---|---|
Node.js) 백준 2512번: 예산 (0) | 2021.12.13 |
Node.js) 백준 2468번: 안전 영역 (0) | 2021.12.13 |
Node.js)백준 4963번: 섬의 개수 (0) | 2021.12.13 |
Node.js) 백준 1476번: 날짜계산 (0) | 2021.12.13 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- MOD
- node.js
- 개발자면접
- 서버개발
- 최소공통조상
- 동적프로그래밍
- 투포인터 연습
- 다이나밍프로그래밍
- 롱베케이션
- 그래프
- 투포인터
- 면접질문
- 은둔청년체험
- create databases;
- 서버점검
- 로드나인
- MySQL
- DB 생성
- create db
- 다이나믹프로그래밍
- 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 |
글 보관함