PAT_A1129#Recommendation System
Source:
Description:
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
queryis the item that the user is accessing, andrec[i](i=1, ... K) is thei-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
Keys:
- 快乐模拟
Attention:
- 在线处理
- cmp引用传参
- 其实运算符重载也是可以的
Code:
/*
Data: 2019-08-11 21:13:07
Problem: PAT_A1129#Recommendation System
AC: 43:20 题目大意:
推荐系统会预测用户对于商品的喜好程度,现在通过用户获取商品的次数来评估用户的喜好程度
输入:
第一行给出,查询次数N<=5e4,系统给出推荐最大数量K<=10
第二行给出,用户依次查询的商品编号(1~N)
输出:
当前搜索编号:推荐商品编号 <=k
*/
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int M=1e6;
int h[M]={},t[M]={}; bool cmp(const int &a, const int &b)
{
if(t[a] != t[b])
return t[a] > t[b];
else
return a < b;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n,k,x;
vector<int> recmd;
scanf("%d%d", &n, &k);
for(int i=; i<n; i++)
{
scanf("%d", &x);
if(i!=)
{
printf("%d: ", x);
for(int i=; i<recmd.size(); i++)
printf("%d%c", recmd[i], i==recmd.size()-?'\n':' ');
}
t[x]++;
if(recmd.size()<k && h[x]==)
{
recmd.push_back(x);
h[x]=;
}
else if(recmd.size()==k && h[x]==)
{
if(t[x]>t[recmd[k-]] || (t[x]==t[recmd[k-]] && x<recmd[k-]) )
{
h[recmd[k-]]=;
h[x]=;
recmd[k-]=x;
}
}
sort(recmd.begin(),recmd.end(),cmp);
} return ;
}
PAT_A1129#Recommendation System的更多相关文章
- 海量数据挖掘MMDS week4: 推荐系统Recommendation System
http://blog.csdn.net/pipisorry/article/details/49205589 海量数据挖掘Mining Massive Datasets(MMDs) -Jure Le ...
- PAT1129:Recommendation System
1129. Recommendation System (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- A1129. Recommendation System
Recommendation system predicts the preference that a user would give to an item. Now you are asked t ...
- PAT A1129 Recommendation System (25 分)——set,结构体重载小于号
Recommendation system predicts the preference that a user would give to an item. Now you are asked t ...
- 1129 Recommendation System
1129 Recommendation System (25 分) Recommendation system predicts the preference that a user would gi ...
- PAT甲级 1129. Recommendation System (25)
1129. Recommendation System (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- PAT 1129 Recommendation System[比较]
1129 Recommendation System(25 分) Recommendation system predicts the preference that a user would giv ...
- PAT 甲级 1129 Recommendation System
https://pintia.cn/problem-sets/994805342720868352/problems/994805348471259136 Recommendation system ...
- 1129 Recommendation System (25 分)
Recommendation system predicts the preference that a user would give to an item. Now you are asked t ...
随机推荐
- Linux排查java程序占用cpu过高的线程代码
分几步骤: 1.通过top,查出占用CPU过高的java进程 ,比如: pid :6666 2.通过ps -mp 6666 -o THREAD,tid,time| sort -n -k1 -r 查看此 ...
- Oracle-时间与字符串转换
--UPDATE_TIME 是时间,直接转成字符串 SELECT to_char(MAX(UPDATE_TIME), 'yyyy-mm-dd hh24:mi:ss') as lastUpdateTim ...
- 关于卷积网络以及反卷积网络shape的计算
CNN的计算方式: w1 = (w - F_w + 2p) / s_w + 1 h1 = (h - F_h + 2p) / s_h + 1 其中 w, h 分别为上一层的宽高, Filters(ker ...
- 【SSH之旅】一步步学习Hibernate框架(一):关于持久化
在不引用不论什么框架下,我们会通过平庸的代码不停的对数据库进行操作,产生了非常多冗余的可是又有规律的底层代码,这样频繁的操作数据库和大量的底层代码的反复书写极大的浪费了程序人员的书写.就在这样一种情况 ...
- 大型项目开发: 隔离 (《大规模C++程序设计》书摘)
书中第六章 隔离. 主要在撰述什么须要定义在头文件?什么应当移到编译单元中? 核心仍然是先区分接口定义与实现细节.实现细节的改变会导致客户代码的又一次编译,从逻辑上也表示与客户代码间可能存在着强耦合. ...
- 关东升的《从零開始学Swift》即将出版
大家好: 苹果2015WWDC大会公布了Swift2.0,它较之前的版本号Swift1.x有非常大的变化.所以我即将出版<从零開始学Swift><从零開始学Swift>将在&l ...
- 使用excel进行数据挖掘(4)---- 突出显示异常值
使用excel进行数据挖掘(4)---- 突出显示异常值 在配置环境后.能够使用excel进行数据挖掘. 环境配置问题可參阅: http://blog.csdn.net/xinxing__8185/a ...
- Golang Template source code analysis(Parse)
This blog was written at go 1.3.1 version. We know that we use template thought by followed way: fun ...
- Delphi研究,对全局变量函数与OOP编程关系的一点体会 good
感叹:设计VCL的人真是神人啊,感觉比Pascal编译器的设计人还要牛很多,把整个Windows架构理了一遍,封装的如此之好,复用的如此之好(以至于Delphi的控件满天飞,使用还特别容易),简直惊为 ...
- RCF:一个相当不错的C++分布式RPC框架
RCF(远程调用框架)是一个可以移植的C++进程间通信框架,使用C++语言特性,提供了一个简单高效的编写分布式C++软件的途径.RCF利用编译时多态清晰分开了接口和实现. 和传统的RPC框架如CORB ...