1 #pragma warning(disable:4996)
2 #define _CRT_SECURE_NO_WARNINGS
3
4 #include <iostream>
5 #include <map>
6 #include <set>
7 using namespace std;
8 struct node
9 {
10 int ind, num;
11 node(int x) :ind(x){}
12 node(int x, int y):ind(x), num(y){}
13 bool operator < (const node& a)const
14 {
15 return num != a.num ? num > a.num : ind < a.ind;
16 }
17 };
18 //int book[50001];
19 int main()
20 {
21 int n, k;
22 cin >> n >> k;
23 set<node> s;
24 for (int i = 0; i < n; ++i)
25 {
26 int a;
27 scanf("%d", &a);
28 if (i != 0)
29 {
30 printf("%d:", a);
31 int cnt = 0;
32 for (auto it = s.begin(); it != s.end() && cnt < k; ++cnt, ++it)
33 {
34 printf(" %d", it->ind);
35 }
36 cout << endl;
37 }
38 auto it = s.find({ node(a), });//找到下标为a的元素
39 if (it != s.end())
40 {
41 s.erase(it);
42 }
43 int t = it->num;
44 s.insert({ node(a, t+1)});
45 }
46 return 0;
47 }
1129 Recommendation System (25 分)
最新推荐文章于 2021-05-12 16:20:35 发布