Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
Tags
- ๋ฐฑ์ค 2108 ์๋ฐ์คํฌ๋ฆฝํธ
- ์ค์ฝํ
- ๋ฐฑ์ค 1339๋ฒ js
- ์๋ฐ์คํฌ๋ฆฝํธ ์ค์ฝํ
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง ํ๊ณ
- js ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- app router emotion
- js
- js ์ค์ฝํ
- ๋ฐฑ์ค 1339๋ฒ ์๋ฐ์คํฌ๋ฆฝํธ
- js ๋ฌธ์์ด ์์ถ
- ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ์์ด ์์ถ
- suspense ๋์์๋ฆฌ
- ํ๋ก๊ทธ๋๋จธ์ค ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ์ฌ์ฉ์ฑ ๊ฐ์
- emtion app router
- suspense react-query
- ํ๋ก๊ทธ๋๋จธ์ค ๋ฌธ์์ด ์์ถ
- ๋ฆฌ์กํธ์ฟผ๋ฆฌ suspense
- suspense ๋ณ๋ชฉํ์
- ์นด์นด์ค ์ฝํ
- ๋ฐฑ์ค 1339๋ฒ nodejs
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง
- suspense ๋น๋๊ธฐ
- TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more:
- ๋ฐฑ์ค 2108 nodejs
- ๊ตฌ๋ฆํค
- ์ต์ ๋์ฒด์ด๋
- emotion RSC
- next13 emotion
Archives
- Today
- Total
Lennon FE
[๋ฐฑ์ค 10816๋ฒ] ์ซ์ ์นด๋2 - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) ๋ณธ๋ฌธ
๐ฅ Algorithm/Baekjoon
[๋ฐฑ์ค 10816๋ฒ] ์ซ์ ์นด๋2 - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs)
Lennon 2022. 2. 3. 19:57728x90
๋ฐ์ํ
https://www.acmicpc.net/problem/10816
const fs = require('fs');
const input = fs.readFileSync('dev/stdin').toString().trim().split('\n');
const binarySearch = (arr, num) => {
let start = 0;
let end = arr.length - 1;
while (start <= end) {
let middle = Math.floor((start + end) / 2);
if (arr[middle][0] < num) {
start = middle + 1;
} else if (arr[middle][0] > num) {
end = middle - 1;
} else {
return arr[middle][1];
}
}
return 0;
};
const haveCard = input[1]
.split(' ')
.sort((a, b) => a - b)
.map(Number);
const isCard = input[3].split(' ').map(Number);
const arr = [[haveCard[0], 1]];
for (let i = 1; i < haveCard.length; i++) {
if (haveCard[i - 1] === haveCard[i]) {
arr[arr.length - 1][1]++;
} else {
arr.push([haveCard[i], 1]);
}
}
const answer = isCard.map((v) => {
return binarySearch(arr, v);
});
console.log(answer.join(' '));
binarySearch => ์ด๋ถ ํ์ ํจ์
๋จผ์ ๊ฐ์ง๊ณ ์๋ ์ซ์ ์นด๋ ๋ฐฐ์ด์ ์์ ์์๋๋ก ์ ๋ ฌํ๊ณ , ์ค๋ณต๋ ์นด๋ ๊ฐ์๋ฅผ ์ผ๋ค.
๊ทธ ํ binarySearch๋ฅผ ์ด์ฉํด logN ์๊ฐ๋ณต์ก๋๋ก ๋น ๋ฅด๊ฒ ๊ตฌํด์ฃผ๋ฉด ๋!
๊ทธ๋ฅ ๋ฐ๋ณต๋ฌธ์ผ๋ก ๊ตฌํ๋ฉด ์๊ฐ์ด๊ณผ๊ฐ ๊ฑธ๋ฆด ๊ฒ์ด๋ค.
728x90
๋ฐ์ํ
'๐ฅ Algorithm > Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค 6603๋ฒ] ๋ก๋ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.02.06 |
---|---|
[๋ฐฑ์ค 1920๋ฒ] ์ ์ฐพ๊ธฐ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.02.03 |
[๋ฐฑ์ค 14719๋ฒ] ๋น๋ฌผ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.01.28 |
[๋ฐฑ์ค 3009๋ฒ] ๋ค ๋ฒ์งธ ์ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.01.25 |
[๋ฐฑ์ค 11047๋ฒ] ๋์ 0 - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.01.23 |
Comments