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 ...
随机推荐
- ckplayer iis6 mp4 播放404错误
设置mime. 1.右键网站 2.选择http头 3.点击编辑MIME按钮 4.新增MIME类型 5.在“扩展名”框内输入“mp4”,“MIME类型”框中输入“video/x-mp4” ps:类型不要 ...
- vue缓存之keep-alive,设置想要缓存的页面
由于项目需求从a页面跳转到b页面,返回a页面,a页面数据不能被刷新掉,方法很多列举12 方法1 a页面通过学期按钮切换学期,该学期里more进入b页面,返回a页面,返回回到对应a页面进入的高亮按钮设置 ...
- CSS 图片居中
} .left-logo a { height: 100px; width: 55px; display: block; } .left-logo a img{ height: ; width: 55 ...
- React-router4 第四篇 Custom Link 自定义链接
直接贴代码 虽说我这么懒的人应该不会自定义标签,何必呢,,但是我还是看了官方的例子 直接抄过来, exact 属性:根据我的测试,这个属性应该和路由的精确匹配有关有关,当值为true时,路由是会精确匹 ...
- Navicat连接MySQL,出现2059 - authentication plugin 'caching_sha2_password'的解决方案
昨天当我把MySQL的安装程序下载并安装好,然后又下载了另外一个工具来使用它,该工具的名称是Navicat Premium,当我通过该工具连接MySQL Workbench的时候,无法连接,提示“20 ...
- N! java
import java.util.*; import java.math.*; public class Num2{ public static void main(String args[]){ B ...
- iOS.CocoaPods.0
1. CocoaPods CocoaPods 是Objective-C (iOS and OS X) projects 的依赖管理器. A CocoaPod (singular) is a speci ...
- BZOJ1226或洛谷2157 [SDOI2009]学校食堂
BZOJ原题链接 洛谷原题链接 注意到\(B[i]\)很小,考虑状压\(DP\). 设\(f[i][j][k]\)表示前\(i - 1\)个人已经拿到菜,第\(i\)个人及其后面\(7\)个人是否拿到 ...
- ubuntu下为单个网卡配置多个ip
参考文档: https://www.jb51.net/os/Ubuntu/418951.html https://blog.csdn.net/ying1989920/article/details/4 ...
- [Jmeter] 将参数从Jenkins传递给Jmeter
Configuration in Jmeter Configuration in Jenkins