diff --git a/binary-search/12015/jinho.js b/binary-search/12015/jinho.js new file mode 100644 index 0000000..863706e --- /dev/null +++ b/binary-search/12015/jinho.js @@ -0,0 +1,37 @@ +const fs = require('fs'); +const input = fs.readFileSync('a.txt').toString().trim().split('\n'); + +const N = parseInt(input[0]); +const data = input[1].split(' ').map(e => parseInt(e)); + +const answer = [data[0]]; + +const binarySearch = ( arr, elem ) => { + let left = 0; + let right = arr.length - 1; + let idx; + while( left <= right ){ + let mid = Math.floor((left + right) / 2); + if ( arr[mid] === elem ){ + return -1; + } + else if ( arr[mid] < elem ) { + left = mid + 1; + } + else if ( arr[mid] > elem ) { + right = mid - 1; + } + } + arr[left] = elem; +} + +for (let i=1; i answer[answer.length -1] ){ + answer.push(data[i]); + } + else if ( data[i] < answer[answer.length - 1] ){ + binarySearch(answer, data[i]); + } +} + +console.log(answer.length) \ No newline at end of file diff --git a/binary-search/1300/jinho.js b/binary-search/1300/jinho.js new file mode 100644 index 0000000..499ef35 --- /dev/null +++ b/binary-search/1300/jinho.js @@ -0,0 +1,30 @@ +const fs = require('fs'); +const input = fs.readFileSync('a.txt').toString().trim().split('\n'); + +const N = parseInt(input[0]); +const M = parseInt(input[1]); + +let left = 1; +let right = M; + +const countLessOrEqual = (x) => { + let cnt = 0; + for (let i=1; i count ){ + left = mid + 1; + } else { + right = mid; + } +} + +console.log(left); \ No newline at end of file diff --git a/binary-search/1920/jinho.js b/binary-search/1920/jinho.js new file mode 100644 index 0000000..e95a314 --- /dev/null +++ b/binary-search/1920/jinho.js @@ -0,0 +1,26 @@ +const fs = require('fs'); +const input = fs.readFileSync('/dev/stdin').toString().trim().split('\n'); + +const M = parseInt(input[0]); +const N = parseInt(input[2]); + +const data = input[1].split(' '); +const comparison = input[3].split(' '); + +const obj = {}; +const answer = []; +for(let i=0; i { + let left = 0; + let right = N; + + while ( left < right ){ + let mid = Math.floor((left + right)/2); + if (x > scores[mid]){ + left = mid + 1; + } else { + right = mid ; + } + } + return ranks[left]; +} + +for (let i=N+1; i