欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 旅游 > 推荐算法-小红书2024笔试(codefun2000)

推荐算法-小红书2024笔试(codefun2000)

2025/2/23 7:34:02 来源:https://blog.csdn.net/qq_45332149/article/details/140626256  浏览:    关键词:推荐算法-小红书2024笔试(codefun2000)

题目链接
推荐算法-小红书2024笔试(codefun2000)

题目内容

塔子哥需要设计一套推荐算法。 该算法的核心思想如下,首先给定一个商品清单,其中有每个商品所包含的关键词属性,然后给出用户最近搜索过的一些关键词,请你将包含用户搜索过的更多的关键词的商品排在用户目录的前面。
如果两个商品关键词数量相同,则按商品出现的顺序排序。

输入描述

在这里插入图片描述

输出描述

按照题意顺序输出商品

样例1

输入

2 5
red book game music sigma
mozart 3
book classic music
arcaea 4
red music game hard

输出

arcaea
mozart

提示

模拟题

题解1

#include<bits/stdc++.h>
using namespace std;const int N = 30005;int n, q;
string s;
set<string> keySet;
struct shop{string ss;int num; // 商品关键词数量 int idx; // 商品出现的顺序 bool operator < (const shop& A) const {if(num != A.num) return num > A.num;return idx < A.idx;}
}sh[N];int main(){ios::sync_with_stdio(false);cin>>n>>q;for(int i = 1; i <= q; i++){cin>>s;keySet.insert(s);}for(int i = 1, m; i <= n; i++){cin>>sh[i].ss>>m;sh[i].idx = i;for(int j = 1; j <= m; j++){cin>>s;if(keySet.find(s)!=keySet.end()) sh[i].num++;}}sort(sh + 1, sh + n + 1);for(int i = 1; i <= n; i++){cout<<sh[i].ss<<'\n';}return 0;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词