题型为:12 道选择和 3 道编程题。
选择题暂且不表,均和前端无关,考察计网、操作系统和算法知识。
3 道编程题成绩如下:100% 57% 45%,
以下是编程题代码:
第一题:场景题喝咖啡,改 bug,简单的条件判断就可以搞定
// 大疆第一题 100% let bugs_nums = +read_line(); let improve = +read_line(); let coffee_nums = +read_line(); let total_cost = 0; while(bugs_nums > 0) { let now = +read_line(); total_cost += now; bugs_nums-- } let own_time = 60 * (8 - coffee_nums) + coffee_nums * improve * 60; if(own_time >= total_cost) { if(total_cost > (coffee_nums * improve * 60)) { let leave_time = total_cost - (coffee_nums * improve * 60); print(coffee_nums * 60 + leave_time) } else { print(Math.ceil(total_cost/improve)) } } else { print(0) }第二题:场景题买零食,个人觉得是贪心算法
// 大疆第二题 57% let first_row = read_line().split(' '); let nums = +first_row[0]; let money = +first_row[1]; let list = []; for (let i = 0; i < nums; i++) { list[i] = read_line().split(' '); } // 按单位价格满意度排序 list.sort((a, b) => b[1] / b[0] - a[1] / a[0]); let value = 0; let canIBuy = 0; for (let index = 0; index < nums; index++) { canIBuy = money >= list[index][0] * list[index][2] ? list[index][2] : Math.floor(money / list[index][0]); money = money - list[index][0] * canIBuy; value += list[index][1] * canIBuy; canIBuy = 0; } print(value)第三题:单词搜索II(原题)
// 大疆第三题 45% let first_num = +read_line(); let alphabet = [], words = []; while (first_num > 0) { // 字幕表 alphabet.push(read_line().split("")) first_num-- } let second_nums = +read_line(); while (second_nums > 0) { let now = read_line(); words.push(now); second_nums-- } var findWords = function (board, words) { let res = [], row = board.length, col = board[0].length; const getTrie = words => { let root = Object.create(null); for (let word of words) { let node = root; for (let c of word) { if (!node[c]) node[c] = Object.create(null); node = node[c] } node.word = word; } return root } const search = (trie, x, y) => { if (trie.word) { res.push(trie.word) trie.word = null; } if (x < 0 || y < 0 || y >= row || x >= col) return if (!trie[board[y][x]]) return let prefixChar = board[y][x]; board[y][x] = "#"; search(trie[prefixChar], x, y - 1); search(trie[prefixChar], x, y + 1); search(trie[prefixChar], x - 1, y); search(trie[prefixChar], x + 1, y); board[y][x] = prefixChar } let trie = getTrie(words); for (let y = 0; y < row; y++) { for (let x = 0; x < col; x++) { search(trie, x, y) } } return res } let result = findWords(alphabet, words); result.forEach(item => print(item))
全部评论
(4) 回帖