
| 铭记于心 | ||
|---|---|---|
| 🎉✨🎉我唯一知道的,便是我一无所知🎉✨🎉 |
众所周知,作为一名合格的程序员,算法 能力 是不可获缺的,并且在算法学习的过程中我们总是能感受到算法的✨魅力✨。
☀️🌟短短几行代码,凝聚无数前人智慧;一个普通循环,即是解题之眼🌟☀️
💝二分,💝贪心,💝并查集,💝二叉树,💝图论,💝深度优先搜索(dfs),💝宽度优先搜索(bfs),💝数论,💝动态规划等等, 路漫漫其修远兮,吾将上下而求索! 希望在此集训中与大家共同进步,有所收获!!!🎉🎉🎉
这是一道考虑「数据结构运用」与「简单设计」的模拟题。
我们可以根据最终的 “结果” 反推数据结构存储格式
function displayTable(orders: string[][]): string[][] {
const foods = new Set<string>();
const tables_to_food_counter = new Map<string, Map<string, number>>();
orders.forEach(function (order) {
const counter = tables_to_food_counter.get(order[1]) ?? new Map();
tables_to_food_counter.set(order[1], counter);
counter.set(order[2], (counter.get(order[2]) ?? 0) + 1);
return foods.add(order[2]);
});
const foodsArr = Array.from(foods);
foodsArr.sort();
const table = [["Table", ...foodsArr]];
tables_to_food_counter.forEach(function (counter, table_id) {
const table_row = [table_id];
foodsArr.forEach(function (food) {
table_row.push(String(counter.get(food) ?? 0));
});
table.push(table_row);
});
table.sort((a, b) => {
if (a[0] === "Table") {
return -1;
}
if (b[0] === "Table") {
return 1;
}
if (Number(a[0]) < Number(b[0])) return -1;
if (Number(a[0]) > Number(b[0])) return 1;
🌹写在最后💖:
相信大家对今天的集训内容的理解与以往已经有很大不同了吧,或许也感受到了算法的魅力,当然这是一定的,路漫漫其修远兮,吾将上下而求索!伙伴们,明天见!🌹🌹🌹