diff --git "a/Doozuu/231212/pro_\354\204\261\352\262\251\354\234\240\355\230\225\352\262\200\354\202\254.js" "b/Doozuu/231212/pro_\354\204\261\352\262\251\354\234\240\355\230\225\352\262\200\354\202\254.js" new file mode 100644 index 0000000..ef57c8c --- /dev/null +++ "b/Doozuu/231212/pro_\354\204\261\352\262\251\354\234\240\355\230\225\352\262\200\354\202\254.js" @@ -0,0 +1,16 @@ +function solution(survey, choices) { + const map = new Map(); + const types = ['RT', 'CF', 'JM', 'AN'].map((t) => t.split('')); + + function SetScore(t1, t2, score) { + map.set(t1, (map.get(t1) || 0) + Math.abs(score - 4)); + map.set(t2, map.get(t2) || 0); + } + + survey.forEach(([t1, t2], i) => { + const score = choices[i]; + score < 4 ? SetScore(t1, t2, score) : SetScore(t2, t1, score); + }); + + return types.map(([t1, t2]) => (map.get(t1) < map.get(t2) ? t2 : t1)).join(''); +} diff --git "a/Doozuu/231212/pro_\354\226\221\352\263\274\353\212\221\353\214\200.js" "b/Doozuu/231212/pro_\354\226\221\352\263\274\353\212\221\353\214\200.js" new file mode 100644 index 0000000..757b521 --- /dev/null +++ "b/Doozuu/231212/pro_\354\226\221\352\263\274\353\212\221\353\214\200.js" @@ -0,0 +1,28 @@ +function solution(info, edges) { + let answer = 0; + let connectedNode = Array.from({length: info.length}, () => []); + + edges.forEach(([from, to]) => connectedNode[from].push(to)); + + function dfs(currentNode, sheep, wolf, possible) { + let newPossibles = [...possible]; + let currentIndex = newPossibles.indexOf(currentNode); + + info[currentNode] ? wolf++ : sheep++; + + answer = Math.max(answer, sheep); + + if (sheep === wolf) return; + + newPossibles.push(...connectedNode[currentNode]); + newPossibles.splice(currentIndex, 1); + + for (const nextNode of newPossibles) { + dfs(nextNode, sheep, wolf, newPossibles); + } + } + + dfs(0, 0, 0, [0]); + + return answer; +} diff --git "a/Doozuu/231212/pro_\354\235\264\353\252\250\355\213\260\354\275\230\355\225\240\354\235\270\355\226\211\354\202\254.js" "b/Doozuu/231212/pro_\354\235\264\353\252\250\355\213\260\354\275\230\355\225\240\354\235\270\355\226\211\354\202\254.js" new file mode 100644 index 0000000..3557486 --- /dev/null +++ "b/Doozuu/231212/pro_\354\235\264\353\252\250\355\213\260\354\275\230\355\225\240\354\235\270\355\226\211\354\202\254.js" @@ -0,0 +1,32 @@ +function solution(users, emoticons) { + const discountRate = [10, 20, 30, 40]; + const rates = []; + let result = [0, 0]; + + function DFS(depth, arr) { + if (depth === emoticons.length) return rates.push(arr); + for (let i = 0; i < discountRate.length; i++) { + DFS(depth + 1, arr.concat(discountRate[i])); + } + } + DFS(0, []); + + for (const rate of rates) { + let [subscribers, sumPrice] = [0, 0]; + + for (const user of users) { + const [userRate, price] = user; + const ratedPrices = emoticons.reduce((acc, cur, idx) => { + if (rate[idx] >= userRate) return acc + cur * (1 - rate[idx] * 0.01); + return acc; + }, 0); + + if (ratedPrices >= price) subscribers++; + else sumPrice += ratedPrices; + } + + if (subscribers > result[0] || (subscribers === result[0] && sumPrice >= result[1])) result = [subscribers, sumPrice]; + } + + return result; +} diff --git "a/Doozuu/231212/pro_\355\214\214\354\235\274\353\252\205\354\240\225\353\240\254.js" "b/Doozuu/231212/pro_\355\214\214\354\235\274\353\252\205\354\240\225\353\240\254.js" new file mode 100644 index 0000000..352e349 --- /dev/null +++ "b/Doozuu/231212/pro_\355\214\214\354\235\274\353\252\205\354\240\225\353\240\254.js" @@ -0,0 +1,29 @@ +function solution(files) { + function isNumber(n) { + return n !== ' ' && !Number.isNaN(Number(n)); + } + + function Seperate(name) { + let [head, number] = ['', '']; + for (let i = 0; i < name.length; i++) { + if (isNumber(name[i])) { + number += name[i]; + if (!isNumber(name[i + 1])) break; + } else { + head += name[i]; + } + } + return [head, Number(number)]; + } + + return files.sort((a, b) => { + const [head1, number1] = Seperate(a); + const [head2, number2] = Seperate(b); + + if (head1.toUpperCase() === head2.toUpperCase()) { + if (number1 === number2) return; + return number1 - number2; + } + return head1.localeCompare(head2); + }); +}