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
#include<iostream>
#include<set>
using namespace std;
struct node{
int value,cnt;
bool operator< (const node &a) const{
return (cnt != a.cnt) ? cnt > a.cnt : value < a.value;
}
};
int book[]; int main(){
int n,m,num;
scanf("%d%d",&n,&m);
set<node> s;
for(int i = ; i < n; i++){
scanf("%d",&num);
if(i != ){
printf("%d:",num);
int tempCnt = ;
for(auto it = s.begin(); tempCnt < m && it != s.end();it++){
printf(" %d",it->value);
tempCnt++;
}
printf("\n");
}
auto it = s.find(node{num,book[num]});
if(it != s.end()) s.erase(it);
book[num]++;
s.insert(node{num,book[num]});
}
return ;
}

1129 Recommendation System (25 分)的更多相关文章

  1. PAT甲级 1129. Recommendation System (25)

    1129. Recommendation System (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

  2. 1129. Recommendation System (25)

    Recommendation system predicts the preference that a user would give to an item. Now you are asked t ...

  3. PAT甲题题解-1129. Recommendation System (25)-排序

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789819.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  4. 1129 Recommendation System

    1129 Recommendation System (25 分) Recommendation system predicts the preference that a user would gi ...

  5. PAT 1129 Recommendation System[比较]

    1129 Recommendation System(25 分) Recommendation system predicts the preference that a user would giv ...

  6. PAT 甲级 1129 Recommendation System

    https://pintia.cn/problem-sets/994805342720868352/problems/994805348471259136 Recommendation system ...

  7. PAT 1129 Recommendation System

    Recommendation system predicts the preference that a user would give to an item. Now you are asked t ...

  8. PAT1129:Recommendation System

    1129. Recommendation System (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

  9. PAT_A1129#Recommendation System

    Source: PAT A1129 Recommendation System (25 分) Description: Recommendation system predicts the prefe ...

随机推荐

  1. ROS naviagtion analysis: costmap_2d--LayeredCostmap

    博客转自:https://blog.csdn.net/u013158492/article/details/50490490 在数据成员中,有两个重要的变量:Costmap2D costmap_和 s ...

  2. 2.sql分类

    SQL DML 和 DDL 可以把 SQL 分为两个部分:数据操作语言 (DML) 和 数据定义语言 (DDL). SQL (结构化查询语言)是用于执行查询的语法.但是 SQL 语言也包含用于更新.插 ...

  3. EZOJ #201

    传送门 分析 这个题和寿司晚宴有点像 我们知道大于$\sqrt n$的质因子最高就是一次 于是我们对所有数以他的大质数为关键字排序 设dp[i][p2][p3][p5][p7][p11][p13][0 ...

  4. loj2512 [BJOI2018]链上二次求和

    传送门 分析 咕咕咕 代码 #include<iostream> #include<cstdio> #include<cstring> #include<st ...

  5. Java IO RandomAccessFile 任意位置读/写

    随机读写类 RandomAccessFile的唯一父类是Object,与其他流父类不同.是用来访问那些保存数据记录的文件的,这样你就可以用seek( )方法来访问记录,并进行读写了.这些记录的大小不必 ...

  6. 求数列中第K大的数

    原创 利用到快速排序的思想,快速排序思想:https://www.cnblogs.com/chiweiming/p/9188984.html array代表存放数列的数组,K代表第K大的数,mid代表 ...

  7. oracle 中用法dual

    dual是一个虚拟表,用来构成select的语法规则,oracle保证dual里面永远只有一条记录.我们可以用它来做很多事情. dual是一个虚拟表,用来构成select的语法规则,oracle保证d ...

  8. DB2 函数快速构造测试数据

    函数快速构造测试数据 [案例]使用DB2内置函数快速构造测试数据 无论您是在用原型证明某一概念,还是开发一个全新的应用程序,或者只是学习 SQL,您都需要在您的应用程序上运行测试数据.为了有效地测试应 ...

  9. 七月小说网 Python + GraphQL (三)

    概述 后台数据库几个基本表基本搭建完毕,看了下Github Develop的V4 Api抛弃了RESTful,采用GraphQL,感觉很有意思,一看文档,竟然有Python的开源实现 Graphene ...

  10. C#中base的作用

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...