团体天梯练习 L2-021 点赞狂魔

发布时间 2023-04-18 16:42:01作者: Amαdeus

L2-021 点赞狂魔

微博上有个“点赞”功能,你可以为你喜欢的博文点个赞表示支持。每篇博文都有一些刻画其特性的标签,而你点赞的博文的类型,也间接刻画了你的特性。然而有这么一种人,他们会通过给自己看到的一切内容点赞来狂刷存在感,这种人就被称为“点赞狂魔”。他们点赞的标签非常分散,无法体现出明显的特性。本题就要求你写个程序,通过统计每个人点赞的不同标签的数量,找出前 3 名点赞狂魔。

输入格式:

输入在第一行给出一个正整数 \(N\)\(≤100\) ),是待统计的用户数。随后 \(N\) 行,每行列出一位用户的点赞标签。格式为“ \(Name\) \(K\) \(F_{1}\)\(F_{K}\) ”,其中 \(Name\) 是不超过8个英文小写字母的非空用户名,\(1≤K≤1000\)\(F_{i}\)\(i=1, ⋯ ,K\) )是特性标签的编号,我们将所有特性标签从 1 到\(10^{7}\) 编号。数字间以空格分隔。

输出格式:

统计每个人点赞的不同标签的数量,找出数量最大的前3名,在一行中顺序输出他们的用户名,其间以1个空格分隔,且行末不得有多余空格。如果有并列,则输出标签出现次数平均值最小的那个,题目保证这样的用户没有并列。若不足3人,则用 "-" 补齐缺失,例如 mike jenny - 就表示只有2人。

输入样例:

5
bob 11 101 102 103 104 105 106 107 108 108 107 107
peter 8 1 2 3 4 3 2 5 1
chris 12 1 2 3 4 5 6 7 8 9 1 2 3
john 10 8 7 6 5 4 3 2 1 7 5
jack 9 6 7 8 9 10 11 12 13 14

输出样例:

jack chris john


解题思路

水题。统计每个人的点赞的博客篇数,这个只要用 \(set\) 自动判一下重即可,然后计算平均值,平均值只要 \(点赞总数/博客篇数\) ,最后自定义排序一下输出前三个姓名即可。

/*   一切都是命运石之门的选择  El Psy Kongroo  */
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<cmath>
#include<functional>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<double, double> pdd;
typedef pair<string, int> psi;
typedef __int128 int128;
#define PI acos(-1.0)
#define x first
#define y second
//int dx[4] = {1, -1, 0, 0};
//int dy[4] = {0, 0, 1, -1};
const int inf = 0x3f3f3f3f, mod = 1e9 + 7;


const int N = 110, M = 1010;
struct node{
    string name;
    int blogsum;
    double ave;
}p[N];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int n; cin >> n;
    for(int i = 1; i <= n; i ++ ){
        string s; cin >> s;
        int k; cin >> k;

        set<int> st;
        for(int j = 0; j < k; j ++ ){
            int x; cin >> x;
            st.insert(x);
        }

        p[i] = {s, (int)st.size(), k * 1.0 / (int)st.size()};
    }

    sort(p + 1, p + n + 1, [](node &a, node &b){
        if(a.blogsum != b.blogsum) return a.blogsum > b.blogsum;
        return a.ave < b.ave;
    });

    if(n < 3){
        for(int i = 1; i <= n; i ++ ) cout << p[i].name << ' ';
        for(int i = n + 1; i <= 2; i ++ ) cout << "- ";
        cout << "-";
    }else{
        for(int i = 1; i <= 2; i ++ ) cout << p[i].name << ' ';
        cout << p[3].name;
    }

    return 0;
}