怎么知道公司网站是哪个公司做的,山东省造价信息网官网,wordpress dux5,哪些网站做婚纱摄影文章目录 题目描述与示例题目描述输入描述输出描述示例一输入输出说明 示例二输入输出说明 解题思路代码PythonJavaC时空复杂度 华为OD算法/大厂面试高频题算法练习冲刺训练 题目描述与示例
题目描述
某个开源社区希望将最近热度比较高的开源项目出一个榜单#xff0c;推荐给… 文章目录 题目描述与示例题目描述输入描述输出描述示例一输入输出说明 示例二输入输出说明 解题思路代码PythonJavaC时空复杂度 华为OD算法/大厂面试高频题算法练习冲刺训练 题目描述与示例
题目描述
某个开源社区希望将最近热度比较高的开源项目出一个榜单推荐给社区里面的开发者。
对于每个开源项目开发者可以进行关注(watch)、收藏(star)、fork、提 issue、提交合并请求(MR)等。
数据库里面统计了每个开源项目关注、收藏、fork、issue、MR 的数量开源项目的热度根据这 5 个维度的加权求和进行排序。 H W w a t c h ∗ # w a t c h W s t a r ∗ # s t a r W f o r k ∗ # f o r k W i s s u r e ∗ # i s s u r e W m r ∗ # m r H W_{watch} * \#watch W_{star} * \#starW_{fork} * \#forkW_{issure} * \#issureW_{mr} * \#mr HWwatch∗#watchWstar∗#starWfork∗#forkWissure∗#issureWmr∗#mr H H H表示热度值 W w a t c h W s t a r W f o r k W i s s u r e W m r W_{watch}W_{star} W_{fork}W_{issure} W_{mr} WwatchWstarWforkWissureWmr分别表示 5 个统计维度的权重 # w a t c h # s t a r # f o r k # i s s u r e # m r \#watch \#star\#fork\#issure\#mr #watch#star#fork#issure#mr分别表示 5 个统计维度的统计值。
榜单按照热度值降序排序对于热度值相等的按照项目名字转换为全小写字母后的字典序排序。
输入描述
第一行输入为 N表示开源项目的个数0 N 100。
第二行输入为权重值列表一共 5 个整型值分别对应关注、收藏、fork、issue、MR 的权重权重取值 0 M ≤ 50。
第三行开始接下来的 N 行为开源项目的统计维度每一行的格式为
name nr_watch nr_star nr_fork nr_issue nr_mr其中 name 为开源项目的名字由英文字母组成长度 ≤50其余 5 个整型值分别为该开源项目关注、收藏、fork、issue、MR 的数量数量取值 0 nr ≤ 1000。
输出描述
按照热度降序输出开源项目的名字对于热度值相等的按照项目名字转换为全小写字母后的字典序排序
示例一
输入
4
8 6 2 8 6
camila 66 70 46 158 80
victoria 94 76 86 189 211
anthony 29 17 83 21 48
emily 53 97 1 19 218输出
victoria
camila
emily
anthony说明
排序热度值计算
camila: 668 706 462 1588 80*6 2784
victoria: 948 766 862 1898 211*6 4158
anthony: 298 176 832 218 48*6 956
emily: 538 976 12 198 218*6 2468
根据热度值降序得到结果。
示例二
输入
5
5 6 6 1 2
camila 13 88 46 26 169
grace 64 38 87 23 103
lucas 91 79 98 154 79
leo 29 27 36 43 178
ava 29 27 36 43 178输出
lucas
grace
camila
ava
leo说明
排序热度值计算
camila: 135 886 466 261 169*2 1233
grace: 645 386 876 231 103*2 1299
lucas: 915 796 986 1541 79*2 1829
leo: 295 276 366 431 178*2 922
ava: 295 276 366 431 178*2 922
根据热度值降序对于 leo 和 ava热度值相等按照字典序ava 排在 leo 前面得到结果。
解题思路
本题考察编程基础和阅读理解。对于每一个项目名字我们都能够根据公式计算得到一个总热度。先根据热度进行降序排序相同热度的项目再根据全小写的项目名字进行字典序升序排序。
代码
Python
# 题目【排序】2023C-开源项目热榜
# 分值100
# 作者许老师-闭着眼睛学数理化
# 算法模拟/排序
# 代码看不懂的地方请直接在群上提问n int(input())
# 输入五个维度的权重
w1, w2, w3, w4, w5 map(int, input().split())lst list()
for _ in range(n):# 输入项目名字以及该项目各个维度的统计值name, a1, a2, a3, a4, a5 input().split()# 根据公式计算结果total w1*int(a1) w2*int(a2) w3*int(a3) w4*int(a4) w5*int(a5)# 将项目名字和结果以二元组的形式存入lst种lst.append((name, total))# 先根据每一个项目的total值进行降序排序
# 再根据name的全小写形式升序排序
lst.sort(key lambda x: (-x[1], x[0].lower()))# 逐行输出
for name, total in lst:print(name)Java
import java.util.*;public class Main {public static void main(String[] args) {Scanner scanner new Scanner(System.in);int n scanner.nextInt();scanner.nextLine();int w1, w2, w3, w4, w5;w1 scanner.nextInt();w2 scanner.nextInt();w3 scanner.nextInt();w4 scanner.nextInt();w5 scanner.nextInt();scanner.nextLine();ListMap.EntryString, Integer list new ArrayList();for (int i 0; i n; i) {String[] input scanner.nextLine().split( );String name input[0];int a1 Integer.parseInt(input[1]);int a2 Integer.parseInt(input[2]);int a3 Integer.parseInt(input[3]);int a4 Integer.parseInt(input[4]);int a5 Integer.parseInt(input[5]);int total w1 * a1 w2 * a2 w3 * a3 w4 * a4 w5 * a5;list.add(new AbstractMap.SimpleEntry(name, total));}Collections.sort(list, (a, b) - {if (!a.getValue().equals(b.getValue())) {return Integer.compare(b.getValue(), a.getValue());}return a.getKey().toLowerCase().compareTo(b.getKey().toLowerCase());});for (Map.EntryString, Integer entry : list) {System.out.println(entry.getKey());}}
}C
#include iostream
#include vector
#include algorithmusing namespace std;int main() {int n;cin n;int w1, w2, w3, w4, w5;cin w1 w2 w3 w4 w5;vectorpairstring, int lst;for (int i 0; i n; i) {string name;int a1, a2, a3, a4, a5;cin name a1 a2 a3 a4 a5;int total w1 * a1 w2 * a2 w3 * a3 w4 * a4 w5 * a5;lst.push_back(make_pair(name, total));}sort(lst.begin(), lst.end(), [](const pairstring, int a, const pairstring, int b) {if (a.second ! b.second) {return b.second a.second;}return a.first b.first;});for (const auto p : lst) {cout p.first endl;}return 0;
}时空复杂度
时间复杂度O(NlogN)。排序所需时间复杂度。
空间复杂度O(N)。 华为OD算法/大厂面试高频题算法练习冲刺训练 华为OD算法/大厂面试高频题算法冲刺训练目前开始常态化报名目前已服务100同学成功上岸 课程讲师为全网50w粉丝编程博主吴师兄学算法 以及小红书头部编程博主闭着眼睛学数理化 每期人数维持在20人内保证能够最大限度地满足到每一个同学的需求达到和1v1同样的学习效果 60天陪伴式学习40直播课时300动画图解视频300LeetCode经典题200华为OD真题/大厂真题还有简历修改、模拟面试、专属HR对接将为你解锁 可上全网独家的欧弟OJ系统练习华子OD、大厂真题 可查看链接 大厂真题汇总 OD真题汇总(持续更新) 绿色聊天软件戳 od1336了解更多