Return to the Ladder-L2-021 Like Crazy Demon (25 points)

Topic description

There is a "Like" function on Weibo, where you can support your favorite blog posts by liking them. Each blog post has some tags that describe its characteristics, and the type of blog post you like also indirectly describes your characteristics. However, there is such a person who will madly brush their presence by liking everything they see. This kind of person is called a "like madman". The hashtags they like are so scattered that they don't show any obvious character. This question requires you to write a program to find the top 3 likes by counting the number of different tags that each person likes.

Input format:

The input gives a positive integer N (≤100) in the first line, which is the number of users to be counted. Next N lines, each listing a user's like tag. The format is "Name KF 1 ⋯ FK ", where Name is a non-empty user name with no more than 8 English lowercase letters, 1≤K≤1000, F i (i=1,⋯,K) is the number of the feature label, we Number all feature labels from 1 to 10^7. The numbers are separated by spaces.

Output format:

Count the number of different tags liked by each person, find the top 3 with the largest number, and output their user names in sequence in one line, separated by 1 space, and there must be no extra space at the end of the line. If there is a tie, the one with the smallest average number of occurrences总共点赞次数最小 of the label is output, and the question ensures that such users are not tied. If there are less than 3 people, use - to fill in the missing, for example, mike jenny - means there are only 2 people.

Input sample:

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

Sample output:

jack chris john

Sorting, water questions, but you must understand the meaning of the questions.
After deduplication, if the number of likes is the same, the average value should be minimized, that is, as long as the original number is the smallest, the solution to the problem can be obtained.

#include <iostream>
#include <algorithm>
#include <set>

using namespace std;

const int N = 110;

struct Person {
    
    
    string name;
    int cnt; // 去重后的数量
    int avg; // 总数量
    
    bool operator< (const Person& w) const {
    
    
        return cnt > w.cnt || cnt == w.cnt && avg < w.avg;
    }
        
}user[N];

int n;

int main() {
    
    
    cin >> n;
    
    for (int i = 0; i < n; i++) {
    
    
        string name;
        int k;
        cin >> name >> k;
        set<int> s;
        for (int j = 0; j < k; j++) {
    
    
            int x;
            cin >> x;
            s.insert(x);
        }
        user[i] = {
    
    name, s.size(), k};
    }
    
    sort(user, user + n);
    if (n >= 3) {
    
    
        cout << user[0].name << ' ' << user[1].name << ' ' << user[2].name;
    } else if (n == 2) {
    
    
        cout << user[0].name << ' ' << user[1].name << " -";
    } else if (n == 1) {
    
    
        cout << user[0].name << " - -";
    }
    
    
    return 0;
}

Return to the Ladder-L2-021 Like Crazy Demon (25 points)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324033926&siteId=291194637