PAT 甲级1129
本题让我学会了重载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相关推荐
- PAT甲级1129 Recommendation System:[C++题解]统计前k个商品
文章目录 题目分析 题目来源 题目分析 来源:acwing 分析: 用变量k来计数每次输出前k个,k等于min(k,m),m为系统允许的最大推荐数. 用数组cnt统计每件商品的数量,top数组统计前k ...
- PAT甲级考试题库题目分类
PAT甲级题目分类 水题 1136.1139.1143.1148 字符串处理 1001.1005.1035.1061.1073.1077.1082. 1108.1140.1152 模拟 1002.10 ...
- PAT甲级题目解析和知识点分类整理
转载请注明出处 个人博客:https://maxusun.github.io/ 今天整理电脑,发现了去年为了考研浙大计算机整理的PAT资料.现在考研已经尘埃落定.想到当时盲目刷题浪费了好多时间,在这里 ...
- PAT甲级(Advanced Level)真题--1046 Sharing
PAT甲级(Advanced Level)真题–1046 Sharing 通过:648 提交:1138 通过率:56% To store English words, one method is to ...
- 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 ...
- 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 ...
- Pat甲级 1002 A+B for Polynomials
Pat甲级 1002 A+B for Polynomials 思路 代码 题目网址 https://pintia.cn/problem-sets/994805342720868352/problems ...
- Pat甲级 1001 A+B Format
Pat甲级 1001 A+B Format 思路 代码 题目网址 https://pintia.cn/problem-sets/994805342720868352/problems/99480552 ...
- PAT甲级1055 The World‘s Richest:[C++题解]k路归并
文章目录 题目分析 题目来源 题目分析 来源:acwing 分析: 采用二维数组vector[N]来存每个年龄的人(结构体),然后分别从大到小排序.剩下的任务就是从给定的年龄[a ,b]中,k路归并最 ...
最新文章
- input type=range标签用法实例代码
- jvm性能调优实战 - 27亿级数据量的实时分析引擎,为啥频繁发生Full GC
- 官宣:神策 2018 数据驱动大会亮点回顾
- FastDFS 安装
- 上海市二级c语言软件环境,上海市计算机二级C语言复习资料 word整理版.doc
- 使用Spring Integration重试RabbitMQ
- 大型网站HTTPS实践:HTTPS对性能的影响
- 如何卸载mysql server 2005_彻底的卸载SQL Server2005
- 2014传智播客ios第4期基础班+就业班
- bochs运行xp_bochs xp镜像
- 如何使用html制作网页
- 可行性分析与需求分析
- ORCAD原理图检查
- Excel VBA 操作键盘(如:移动方向键,上下左右等)
- 谷歌浏览器打印不弹出预览直接打印机打印
- 摄影测量:ERDAS自动、手动和导入特征点对(超详细)
- 二、Eureka之server端集群节点发现,数据同步
- AD,Altium designer
- python 错误--UnboundLocalError: local variable 'num' referenced before assignment
- 在内卷如此严重的当下,大二小伙逆流而上,首次参加校招成功拿到网易实习offer