zoukankan      html  css  js  c++  java
  • 1129 Recommendation System (25 分)

     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 }
  • 相关阅读:
    linux 查看系统负载:uptime
    centos who命令 查看当前登录系统用户信息
    centos7 管理开机启动:systemd
    Linux ethtool 命令
    Linux ifconfig 命令
    linux centos7 目录
    POJ 1169
    POJ 1163
    POJ 1154
    POJ 1149
  • 原文地址:https://www.cnblogs.com/2020R/p/14423089.html
Copyright © 2011-2022 走看看