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 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:

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.

知识点:STL的使用,排序

思路:每一次输入后,都要让所有元素有序。如果利用线性结构,那么他的时间复杂度是O(n),在数据量大的时候也是不行的。利用STL的set,插入的时间复杂度降为O(logN)

 #include <cstdio>
#include <set>
using namespace std;
const int maxn = ; int clickTime[maxn];
struct nodetype{
int v,cnt;
nodetype(int a,int b) : v(a), cnt(b) {}
bool operator < (const nodetype &a) const {
return (cnt!=a.cnt)?cnt>a.cnt:v<a.v;
}
}; int main(int argc, char *argv[]) {
fill(clickTime,clickTime+maxn,); int n,k,tmp;
scanf("%d %d",&n,&k);
set<nodetype> s;
for(int i=;i<=n;i++){
scanf("%d",&tmp);
if(i!=){
printf("%d:",tmp);
int cnt=;
for(auto it=s.begin();cnt<k&&it!=s.end();it++){
printf(" %d",it->v);
cnt++;
}
printf("\n");
} auto it = s.find(nodetype(tmp,clickTime[tmp]));
if(it!=s.end()){
s.erase(nodetype(tmp,clickTime[tmp]));
}
s.insert(nodetype(tmp,clickTime[tmp]+));
clickTime[tmp]++;
}
}

1129 Recommendation System的更多相关文章

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

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

  2. PAT 1129 Recommendation System[比较]

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

  3. PAT 甲级 1129 Recommendation System

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

  4. 1129 Recommendation System (25 分)

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

  5. PAT 1129 Recommendation System

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

  6. 1129. Recommendation System (25)

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

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

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

  8. PAT1129:Recommendation System

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

  9. 海量数据挖掘MMDS week4: 推荐系统Recommendation System

    http://blog.csdn.net/pipisorry/article/details/49205589 海量数据挖掘Mining Massive Datasets(MMDs) -Jure Le ...

随机推荐

  1. avalon子孙元素属性监听

    HTML正文: <body ms-controller="ex"> <div class="ms-hover" ms-click=" ...

  2. 访问WebServcie遇到配额不足的时候,请增加配额

    常常遇到的报错: 1.错误一: Error in deserializing body of reply message for operation 'GetArticleInfo'.,StackTr ...

  3. python 数据类型 总结

    按存储空间的占用分(从低到高) 数字 字符串 集合:无序,即无序存索引相关信息 元组:有序,需要存索引相关信息,不可变 列表:有序,需要存索引相关信息,可变,需要处理数据的增删改 字典:无序,需要存k ...

  4. Java 7.35 游戏:猜字游戏(C++&Java)

    Ps: 有人可能好奇我为什么大费周章的去写主函数,而不直接把所有操作放在类中,Why?类就好比骨干(存放核心的数据和功能),最好提供接口, 避免了类中的输入输出,当然,这也不是绝对的. C++: #i ...

  5. javascript 高级程序设计 九

    JS 面向对象的程序设计思想(1)深入理解JS对象 1.js的中没有OO语言中的'类'的概念.ECMAjs中把对象定义为:‘无序属性的集合,其属性可以包含基本值,对象或函数’. 2.ECMAScrip ...

  6. 06. pt-duplicate-key-checker

    | t01 | CREATE TABLE `t01` ( `pkid` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT ...

  7. 网卡驱动如何设置组播MAC地址

    参考资料: https://blog.csdn.net/abccheng/article/details/50465268 将网卡加入到组播组中.

  8. 来看看N多设计师笔下的Spider Man

    很多电影在大获成功后,其中的人物都成了火热的IP,漫威的各类超级英雄就是个很好的例子,今天突发奇想看看各种漫画人物在插画师手中同一人物会有什么样的不同,所以以蜘蛛侠为主题,搜集了很多插画师笔下的蜘蛛侠 ...

  9. soapui groovy脚本汇总

    出处:https://www.jianshu.com/p/ce6f8a1f66f4 一.一些内部元件的访问 testRunner.testCase开头 1.向下访问 testRunner.testCa ...

  10. rabbitmq安装.教程

    https://www.cnblogs.com/ericli-ericli/p/5902270.html (rabbitmq安装)https://www.cnblogs.com/iiwen/p/538 ...