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 ...
随机推荐
- rviz1
msckf_vio ####查看topic列表:wj@wj-Inspiron-5437:~$ rostopic list/benchmark_publisher/path/cam0/image_raw ...
- PAT 1032 挖掘机技术哪家强(20)(有测试样例)
1032 挖掘机技术哪家强(20)(20 分) 为了用事实说明挖掘机技术到底哪家强,PAT组织了一场挖掘机技能大赛.现请你根据比赛结果统计出技术最强的那个学校. 输入格式: 输入在第1行给出不超过10 ...
- SoftwareEngineering.APIDesign.iOS
API Design for iOS/Mac (Objective-c Edition) 1. UI Control Library API的设计 和已有组件保持一致(例如: 使用标准的API, 模型 ...
- iOS.Notification.Bar.Color
Reference: http://apple.stackexchange.com/questions/44246/what-determines-the-special-color-of-the-s ...
- HapMap
HapMap五周年回顾 2011-01-12 | 作者: [关闭] 作者简介:曾长青,中国科学院北京基因组所研究员,博士生导师.CUSBEA奖学金.百人计划.杰出青年基金.首批新世纪百千万人才工程国家 ...
- Codeforces559C Gerald and Giant Chess
一道计数类\(DP\) 原题链接 我们可以先计算从左上角到右下角总的路径,再减去经过黑色方格的路径即是答案. 总路径数可以用组合数直接计算:\(C_{H+W-2}^{H-1}\) 因为从左上角到右下角 ...
- 爬取掌阅app免费电子书数据
主要介绍如何抓取app数据及抓包工具的使用,能看到这相信你已经有爬虫基础了 编不下去了,主要是我懒,直接开干吧! 一.使用环境和工具 windows + python3 + Jsonpath + Ch ...
- BZOJ 1791: [IOI2008]Island 岛屿 - 基环树
传送门 题解 题意 = 找出无向基环树森林的每颗基环树的直径. 我们首先需要找到每颗基环树的环, 但是因为是无向图,用tarjan找环, 加个手工栈, 我也是看了dalao的博客才知道tarjan找无 ...
- boost asio 一个聊天的基本框架
示例代码 #include "Util.h" #include "MyAsio.h" #include "TcpConnectionManager.h ...
- 跟我学Spring Boot(二)Hello World
1.打开DemoApplication添加如下代码 package com.example; import org.springframework.boot.SpringApplication; im ...