1129 Recommendation System (25 point(s))

AI 赋能测试全生命周期:多 Agent 协同的自动化提效方案 本文提出了一种基于Coze平台的多Agent协同测试解决方案,旨在解决软件测试中PRD解析不清晰、测试点覆盖不全、用例编写效率低、代码生成耗时等痛点。通过PRD优化、测试点生成、测试用例生成和单元测试框架生成四个Agent的协同工作,结合Cursor工具实现从需求到代码的全链路自动化。以电商平台登录模块为例,展示了从模糊PRD到标准化测试用例和可执行Java单元测试代码的完整转化流程。该方案通过AI赋能显著提升测试效率,减少人工干预,实现测试覆盖率≥95%,为快速迭代的软件研发提供了高效的测试自动化支持。 阅读详情

1129 Recommendation System (25 point(s))

Recommendation system predicts the preference that a user would give to an item. Now you are asked to program a very simple recommendation system that rates the user's preference by the number of times that an item has been accessed by this user.

Input Specification:

Each input file contains one test case. For each test case, the first line contains two positive integers: N (≤ 50,000), the total number of queries, and K (≤ 10), the maximum number of recommendations the system must show to the user. Then given in the second line are the indices of items that the user is accessing -- for the sake of simplicity, all the items are indexed from 1 to N. All the numbers in a line are separated by a space.

Output Specification:

For each case, process the queries one by one. Output the recommendations for each query in a line in the format:

query: rec[1] rec[2] ... rec[K]

where query is the item that the user is accessing, and rec[i] (i=1, ... K) is the i-th item that the system recommends to the user. The first K items that have been accessed most frequently are supposed to be recommended in non-increasing order of their frequencies. If there is a tie, the items will be ordered by their indices in increasing order.

Note: there is no output for the first item since it is impossible to give any recommendation at the time. It is guaranteed to have the output for at least one query.

Sample Input:

12 3
3 5 7 5 5 3 2 1 8 3 8 12

Sample Output:

5: 3
7: 3 5
5: 3 5 7
5: 5 3 7
3: 5 3 7
2: 5 3 7
1: 5 3 2
8: 5 3 1
3: 5 3 1
8: 3 5 1
12: 3 5 8

考察点:STL set的理解和灵活使用

题意:

用户每想购买一件商品,就向他推荐K个商品,这K个商品从他从前的购买过的商品中按照购买次数从高到低的顺序选择K个,如果有购买次数相同的,就按照商品的编号从小到大排序。 

心路历程:

好好写一下做这道题的心路历程。首先,这道题的输出是随着查询的次数而增长的,对于每一次查询,要基于购买次数和下标进行排序,可想而知,如果每一次查询都重新排序,时间复杂度必然太高。需要注意,每一次查询我们还需要修改购买次数,而排序后我们不能够通过下标再访问了,那还需要基于线性结构的查找,这也是很复杂的。

显然,我们需要寻找一种数据结构来维护这个排序,利用红黑树的set自动排序,我们可以对结构体(包括下标和访问次数)重载运算符<来实现。这个方法我在做题的时候也是想到了,但是问题仍然是如何去修改set中的元素呢?因为我们不能够只通过商品下标来查找,于是我们需要额外维护一个数组记录每个商品的访问次数,仅仅是为了我们对set的查询。

似乎一切迎刃而解了,但是set的元素并不能修改,怎么办呢?先删除后插入。

这道题真的学了很多东西,花了一个多小时,参考了大神的做法(https://blog.youkuaiyun.com/richenyunqi/article/details/80173656),对set的理解更加深入了,如何合理高效地利用轮子,真的是机考中的重中之重!

#include<iostream>
#include<map>
#include<algorithm>
#include<set>
using namespace std;
const int MAX = 5e4+7;
struct item{
	int id;int cnt;
	item(int i,int c):id(i),cnt(c){}
	bool operator < (const item &other) const{
		if(cnt!=other.cnt) return cnt>other.cnt;
		else return id<other.id;
	}
};
set<item> s;
int itemCount[MAX]={0};
int main(void){
	int N,K,a;cin>>N>>K;
	for(int i=0;i<N;i++){
		cin>>a;
		if(i>0){
			cout<<a<<":";
			int output = 0;
			for(set<item>::iterator i=s.begin();i!=s.end()&&output<K;i++){
				cout<<" "<<(*i).id;
				output++;
			}
			cout<<endl;
		} 
		set<item>::iterator it = s.find(item(a,itemCount[a]));//寻找在set的红黑树中是否已经有这一项 
		itemCount[a]++;
		if(it!=s.end()){//如果有 
			s.erase(it);// 删除后再插入达到修改的目的 
			s.insert(item(a,itemCount[a]));
		}else{//没有找到 
			s.insert(item(a,itemCount[a])); 
		}
	}
	return 0;
}

 

视频倍速 - 在线调倍速的加速器APP工具 一刀工具箱APP提供一键可将手机上的视频倍速播放,可以调整视频倍速的加速器,调节视频的速度也就是调节视频的播放速度!一键可将手机上的视频倍速播放,可以调整视频倍速的加速器,调节视频的速度也就是调节视频的播放速度!视频倍速-在线调倍速的加速器-一刀工具箱APP。... 阅读详情

相关推荐

避坑指南:Windows下OpenCV摄像头索引混乱问题的3种解决之道

本文详细解析了Windows下OpenCV摄像头索引混乱问题的3种解决方案,包括GUID查询法、DirectShow接口集成和注册表固化技术。针对工业视觉和智能监控场景,提供实战代码和性能优化建议,帮助开发者稳定识别多路摄像头设备,有效解决VideoCapture接口的索引漂移问题。

weixin_30836759的博客 406

1129 Recommendation System

1129 Recommendation System Recommendation system predicts the preference that a user would give to an item. Now you are asked to program a very simple recommendation system that rates the user’s prefe...

ssf_cxdm的博客 311

潜行游戏设计:核心机制与关卡设计解析

潜行游戏作为动作游戏的重要分支,通过视觉遮蔽、声音传播和AI行为树等复杂系统,为玩家提供独特的策略体验。视觉隐蔽系统采用视野锥和光照值的双重判定,声学传播模型模拟距离衰减和材质穿透,而敌人AI行为树则包含巡逻、警戒和团队协作等状态节点。这些技术不仅提升了游戏的真实感和挑战性,还在《合金装备》《刺客信条》等经典作品中得到广泛应用。潜行游戏的关卡设计强调多路径拓扑结构和环境叙事元素,通过沙漏模型和动态难度调节,平衡自由度和开发成本。未来,基于ML的适应性AI和物理模拟的隐蔽系统将成为创新方向。

weixin_42497762的博客 182

1129 Recommendation System (25point(s)) - C语言 PAT 甲级

* 利用数组记录每个编号询问的次数 * 推荐位未满最大值 K,直接进入推荐位,排序输出 * 推荐位已满最大值,仅需要和推荐位的末尾比较 注意: * 每次询问过后,此编号的询问次数才能加 1 * 所以第一次询问时,推荐位为空,什么也不输出 * 题目中,K 最大为 10,所以排序最多只需要排 10 个数,最开始我直接全排序,然后直接超时

有三只土豆 220

超详细!思岚S2激光雷达hector_mapping建图

使用思岚S2激光雷达,在ros平台上利用hector_mapping功能包实现建图功能

m0_50965539的博客 5591

Flotherm XT新手必看:5分钟搞定自然对流热仿真(附案例文件)

本文为Flotherm XT新手提供了自然对流热仿真的快速入门指南,通过详细的步骤解析和实用技巧,帮助用户在5分钟内完成从建模到后处理的全流程。重点介绍了环境设置、几何建模、材料属性、网格划分等关键环节,并附有案例文件供参考学习,助力工程师快速掌握热仿真技术。

weixin_30839881的博客 630

1129 Recommendation System (25 point(s))

题解 set中erase函数的使用。 #include&lt;iostream&gt; #include&lt;set&gt; #include&lt;cstdio&gt; using namespace std; const int MAXN = 5e4 + 10; struct node { int item, cnt; bool operator &lt; (const nod...

徐伯莱 262

Joern实战:从代码导入到Python分析的全流程避坑指南(附常见错误解决方案)

本文详细介绍了Joern静态分析工具从代码导入到Python分析的全流程实践指南,包括环境配置、代码导入技巧、数据库服务优化、Python交互分析及性能调优等关键步骤。特别针对常见错误提供了实用解决方案,帮助开发者高效进行代码安全分析和漏洞挖掘。

weixin_28309571的博客 141

PATA1129题解

// // main.cpp // PATA1129 // // Created by Phoenix on 2018/2/25. // Copyright © 2018年 Phoenix. All rights reserved. // #include #include #include using namespace std; const int maxn = 50010;

Phoenix 394

GEE案例教程:融合Sentinel-1 SAR数据、Sentinel-2光学影像和WorldPop人口数据,构建完整的洪水监测与影响评估工作流

本文介绍了一个专为巴基斯坦哈扎拉分区设计的洪水监测系统,该系统整合了Sentinel-1 SAR数据、Sentinel-2光学影像和WorldPop人口数据等多源遥感数据。系统通过VV极化SAR数据的水体提取算法(阈值-13dB)实现洪水范围监测,结合10米分辨率的光学影像进行可视化验证,并利用100米分辨率人口数据评估受灾人口。系统提供完整的技术实现,包括研究区加载、遥感数据处理、日期选择界面和洪水变化检测等功能模块,为灾害应急响应提供科学依据。

此星光明博客 191

嵌入式工程师成长之路(7)——算法学习

算法大全1、风仲达——算法笔记2、坐在马桶上学算法3、啊哈算法4、深度强化学习实验室。

云轩阁 4万+

1129 Recommendation Systems (25 point(s))

Recommendation system predicts the preference that a user would give to an item. Now you are asked to program a very simple recommendation system that rates the user's preference by the number of time...

张蔡辉 250

Android AVB 分析(十六)5 个例子彻底理解 FEC(Reed-Solomon) 的工作原理

关于 FEC 是如何工作的,一直是我 Android OTA 讨论群中的未解话题,大家基本上都不清楚 Android 上面的 FEC 是如何工作的,为什么在 OTA 升级的最后阶段,FEC 的编码计算会消耗大量的 IO 资源,并持续很长时间。接下来的几篇,我会从一个程序员的角度,演示基于里德所罗门编码的 FEC 到底是如何工作的。

洛奇看世界 669

【PAT】A1129 Recommendation System (25point(s))

文章目录A1129 Recommendation System (25point(s))Input Specification:Output Specification:Sample Input:Sample Output:CodeAnalysis Author: CHEN, Yue Organization: 浙江大学 Time Limit: 400 ms Memory Limit: 64 MB...

Duke 233

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

PTA甲1129 Recommendation System (25 point(s))

文章目录题目原文Input Specification:Output Specification:Sample Input:Sample Output:生词如下:题目大意:思路如下:代码如下: 强烈推荐,刷PTA的朋友都认识一下柳神–PTA解法大佬 不刷也可以认识一下 本文由参考于柳神博客写成 柳神的优快云博客,这个可以搜索文章 柳神的个人博客,这个没有广告,但是不能搜索 还有就是非常非常有用的 算法笔记 全名是 算法笔记 上级训练实战指南 //这本都是PTA的题解算法笔记 PS 今天也要加油鸭

Huangpengyu123的博客 487

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

PAT 甲级 1129 Recommendation System (25 point(s)) set自动排序

题目 题目链接 思路 题目大意:给一个人的选座记录,根据用户以往选择座位的次数来为推荐k个座位,按照选择的次数从大往小推荐,如果次数一样则按id从小到大排序 做法:定义一个结构体,利用set自动排序的特性,每次取前几个元素。更新元素时,需要删除之后再插入 代码 # include<iostream> # include<set> using namespace std; const int maxn = 50010; struct item { int id, cnt

hjyp的博客 180

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

【PAT】1129 Recommendation System (25 分)

Recommendation system predicts the preference that a user would give to an item. Now you are asked to program a very simple recommendation system that rates the user's preference by the number of time...

mdjfk的博客 427

1129 Recommendation System(25 分)(C++)

Recommendation system predicts the preference that a user would give to an item. Now you are asked to program a very simple recommendation system that rates the user's preference by the number of time...

qq_41562704的博客 756

PAT 1129 Recommendation System

原题链接:1129 Recommendation System (25分) 关键词:set、结构体排序 参考的柳神博客:PAT 1129. Recommendation System (25) 甲级 题目大意: 编写一个简单的推荐系统,能够通过分析用户对各种商品的访问次数来预测用户的偏好进行推荐商品。

cwtnice的博客 260

pat甲级 1129 Recommendation System (25分)

文章目录pat甲级 1129 Recommendation System (25分)代码 pat甲级 1129 Recommendation System (25分) note:这道题本身不难,任务简单,就是在线查询排序;但难点在对STL的运用上 ,首先选择合理的容器有两个:map和set,map增删查改更易,重构compare函数或重载操作符很难实现排序;set反之;但增删查改复杂一点容易解决,故只有可选。其次,就是运算符重载或compare函数重写,没有学过的同学可能很困难,学过了就很简单 代码 #in

qq_44992782的博客 258

PAT 1129. Recommendation System (25) 甲级

Recommendation system predicts the preference that a user would give to an item. Now you are asked to program a very simple recommendation system that rates the user’s preference by the number of time

柳婼 の blog 4444

PAT——1129 Recommendation System 甲级

1129 Recommendation System 题目题意代码解析AC代码参考 题目 https://pintia.cn/problem-sets/994805342720868352/problems/994805348471259136 题意 每次浏览前,按照之前的浏览记录进行推荐,推荐次数不大于k,推荐顺序按照物品的浏览次数排序,次数相同按照值升序排列 代码解析 通过运算符重载自定义优先集合,集合(set)中的元素按照指定要求排序。每次输出后,判断当前数字是否在集合中,如果在,就把它拿出来,更新c

ljhsq的博客 210

1129 Recommendation System(25 分)

1129 Recommendation System(25 分) Recommendation system predicts the preference that a user would give to an item. Now you are asked to program a very simple recommendation system that rates the user’...

Neo_2018的博客 810

1129 Recommendation System (25分)

1129 Recommendation System (25分) Recommendation system predicts the preference that a user would give to an item. Now you are asked to program a very simple recommendation system that rates the user’s preference by the number of times that an item has been

Axelrod的博客 312

1129 Recommendation System (25 分)

1129 Recommendation System (25 分) Recommendation system predicts the preference that a user would give to an item. Now you are asked to program a very simple recommendation system that rates the user’s preference by the number of times that an item has bee

shshbdhsjjd的博客 172

1129. Recommendation System

1129. Recommendation System (25)时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueRecommendation system predicts the preference that a user would give to an item. Now you are asked to program ...

ScorpioN___的博客 449
上一篇: 1128 N Queens Puzzle (20 point(s))
下一篇: 1130 Infix Expression (25 point(s))
coderwait
博客等级 码龄9年 20粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值