zoukankan      html  css  js  c++  java
  • A1129 Recommendation System [set自定义排序]

    在这里插入图片描述

    #include<iostream>
    #include<vector>
    #include<map>
    #include<string>
    #include<cstring>
    #include<cstdio>
    #include<algorithm>
    #include<set>
    #include<queue>
    #include<unordered_set>
    using namespace std;
    using namespace std;
    int book[50001];
    struct node {
    	int value, cnt;
    	node(int a, int b) :value(a), cnt(b) {}
    	bool friend operator < (node a,node b)
    	{
    		if (a.cnt != b.cnt)
    			return a.cnt > b.cnt;
    		else
    			return a.value < b.value;
    	}
    };
    int main() {
    	int n, k, num;
    	cin >> n >> k;
    	set<node> s;
    	for (int i = 0; i < n; i++) {
    		cin >> num;
    		if (i != 0) {
    			printf("%d:", num);
    			int tempCnt = 0;
    			for (auto it = s.begin(); tempCnt < k && it != s.end(); it++) {
    				printf(" %d", it->value);
    				tempCnt++;
    			}
    			printf("
    ");
    		}
    		auto it = s.find(node(num, book[num]));
    		if (it != s.end()) s.erase(it);
    		book[num]++;
    		s.insert(node(num, book[num]));
    	}
    	return 0;
    }
    
  • 相关阅读:
    获取comboBox里面的item使用的方法
    QT格式化代码
    按键槽的写法
    int to String
    sprintf在51单片机中的使用
    学习使用MarkDown
    分享9款超酷的jQuery/CSS3插件
    2014年展望
    操作系统面试
    web一点小结
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13811966.html
Copyright © 2011-2022 走看看