1129 Recommendation System
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的更多相关文章
- 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 ...
- PAT 1129 Recommendation System
Recommendation system predicts the preference that a user would give to an item. Now you are asked t ...
- 1129. Recommendation System (25)
Recommendation system predicts the preference that a user would give to an item. Now you are asked t ...
- PAT甲题题解-1129. Recommendation System (25)-排序
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789819.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT1129:Recommendation System
1129. Recommendation System (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- 海量数据挖掘MMDS week4: 推荐系统Recommendation System
http://blog.csdn.net/pipisorry/article/details/49205589 海量数据挖掘Mining Massive Datasets(MMDs) -Jure Le ...
随机推荐
- go语言中的方法method
package main; import "fmt" //重新定义一个类型 //为该INT类型扩展方法 type INT int; type A struct { name str ...
- vue学习视频网址(各种前端视频 网址)
基础信息详解:https://segmentfault.com/blog/vueroad 网址:http://biaoyansu.com/18.1
- python 3.6.5 hashlib 和 hmac 模块
import hashlib m=hashlib.md5()# m=hashlib.sha256() m.update('hello'.encode('utf8'))print(m.hexdigest ...
- Oracle性能优化4-索引
Oracle优化可以分为通过改写sql优化和不改写sql优化不改写sql优化一般通过index来实现 在Oracle数据库中,索引按照索引机制的不同,可以分为三种. 1. B-Tree索引 B-Tre ...
- HDU_2136
#include <iostream> #include <stdio.h> #include <math.h> #include <algorithm> ...
- DNA甲基化测序方法介绍
DNA甲基化测序方法介绍 甲基化 表观遗传学 DNA 甲基化是表观遗传学(Epigenetics)的重要组成部分,在维持正常细胞功能.遗传印记.胚胎发育以及人类肿瘤发生中起着重要作用,是目前新的研究热 ...
- CH#17C 舞动的夜晚
原题链接 即求二分图的不可行边数量,因为不保证是完备匹配,所以需要通过网络流求出任意一组最大匹配,并建立新图判断. 建新图:对于跑完网络流的图上已经匹配的边,建立反边:对于没有匹配的边,建立正边(图只 ...
- if __name__ == '__main__的理解
模块之间引用不能循环成环,圆圈 模块的收搜 !!!把模块当作脚本执行 什么叫模块:py文件,如果一个py文件被导入了,他就是一个模块, 模块没有具体的调用过程 但是能对外提供功能 什么叫脚 ...
- SystemTap 工作原理
<systemtap原理及使用> https://www.cnblogs.com/youngerchina/p/5624588.html 这篇帖子前边系统介绍了systemtap的工作原理 ...
- Maven 下载安装
http://www.runoob.com/maven/maven-tutorial.html https://www.yiibai.com/maven/ Maven 提倡使用一个共同的标准目录结构, ...