本题让我学会了重载C++重载STL中运算符的方法,和在set中二分查找的方法


#include<bits/stdc++.h>
using namespace std;
struct node {int data;int cnt;bool operator <(const node &a) const {return (cnt==a.cnt)?data<a.data:cnt>a.cnt;}
};
int cnt[50005];
int main() {struct node A;int items,n,k,pre;set<node>st;cin>>n>>k;for(int i=0; i<n; i++) {scanf("%d",&items);if(i!=0) {int count=0;printf("%d: ",items);for(set<node>::iterator it=st.begin(); it!=st.end(); it++) {A=*it;count++;printf("%d%c",A.data,count==k||count==st.size()?'\n':' ');if(count==k) break;}}A.data=items;A.cnt=cnt[items];set<node>::iterator it=st.find(A);if(it!=st.end()) st.erase(it);cnt[items]++;A.cnt=cnt[items];st.insert(A);}return 0;
}

PAT 甲级1129相关推荐

  1. PAT甲级1129 Recommendation System:[C++题解]统计前k个商品

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析: 用变量k来计数每次输出前k个,k等于min(k,m),m为系统允许的最大推荐数. 用数组cnt统计每件商品的数量,top数组统计前k ...

  2. PAT甲级考试题库题目分类

    PAT甲级题目分类 水题 1136.1139.1143.1148 字符串处理 1001.1005.1035.1061.1073.1077.1082. 1108.1140.1152 模拟 1002.10 ...

  3. PAT甲级题目解析和知识点分类整理

    转载请注明出处 个人博客:https://maxusun.github.io/ 今天整理电脑,发现了去年为了考研浙大计算机整理的PAT资料.现在考研已经尘埃落定.想到当时盲目刷题浪费了好多时间,在这里 ...

  4. PAT甲级(Advanced Level)真题--1046 Sharing

    PAT甲级(Advanced Level)真题–1046 Sharing 通过:648 提交:1138 通过率:56% To store English words, one method is to ...

  5. PAT甲级(Advanced Level)真题-- 1062 To Buy or Not to Buy

    PAT甲级(Advanced Level)真题-- 1062 To Buy or Not to Buy 通过:643 提交:1220 通过率:52% Eva would like to make a ...

  6. PAT甲级真题 1018 A+B in Hogwarts--python解法

    PAT甲级真题 1018 A+B in Hogwarts 提交:2638 通过:1559 通过率:59% If you are a fan of Harry Potter, you would kno ...

  7. Pat甲级 1002 A+B for Polynomials

    Pat甲级 1002 A+B for Polynomials 思路 代码 题目网址 https://pintia.cn/problem-sets/994805342720868352/problems ...

  8. Pat甲级 1001 A+B Format

    Pat甲级 1001 A+B Format 思路 代码 题目网址 https://pintia.cn/problem-sets/994805342720868352/problems/99480552 ...

  9. PAT甲级1055 The World‘s Richest:[C++题解]k路归并

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析: 采用二维数组vector[N]来存每个年龄的人(结构体),然后分别从大到小排序.剩下的任务就是从给定的年龄[a ,b]中,k路归并最 ...

最新文章

  1. input type=range标签用法实例代码
  2. jvm性能调优实战 - 27亿级数据量的实时分析引擎,为啥频繁发生Full GC
  3. 官宣:神策 2018 数据驱动大会亮点回顾
  4. FastDFS 安装
  5. 上海市二级c语言软件环境,上海市计算机二级C语言复习资料 word整理版.doc
  6. 使用Spring Integration重试RabbitMQ
  7. 大型网站HTTPS实践:HTTPS对性能的影响
  8. 如何卸载mysql server 2005_彻底的卸载SQL Server2005
  9. 2014传智播客ios第4期基础班+就业班
  10. bochs运行xp_bochs xp镜像
  11. 如何使用html制作网页
  12. 可行性分析与需求分析
  13. ORCAD原理图检查
  14. Excel VBA 操作键盘(如:移动方向键,上下左右等)
  15. 谷歌浏览器打印不弹出预览直接打印机打印
  16. 摄影测量:ERDAS自动、手动和导入特征点对(超详细)
  17. 二、Eureka之server端集群节点发现,数据同步
  18. AD,Altium designer
  19. python 错误--UnboundLocalError: local variable 'num' referenced before assignment
  20. 在内卷如此严重的当下,大二小伙逆流而上,首次参加校招成功拿到网易实习offer

热门文章

  1. windows 10 蓝屏解决办法(亲测有用哦!!!)
  2. 继续教育计算机组成原理a试卷,计算机组成原理试卷
  3. mysql数据库sql语句通过DATE_FORMAT格式化日期
  4. 自己做的实时定位系统
  5. 让你的大疆在测绘领域物尽其用
  6. 联想小新pro13 卡顿解决办法
  7. 关于Altium Designer图纸打印记录
  8. 问题:wps表格用鼠标滚轮上下移动表格时,不是平滑移动,而是按单元格跳动的。已解决
  9. HCIE————BGP双平面
  10. Oracle查询提示:未明确定义列