微博上有个“点赞”功能,你可以为你喜欢的博文点个赞表示支持。每篇博文都有一些刻画其特性的标签,而你点赞的博文的类型,也间接刻画了你的特性。然而有这么一种人,他们会通过给自己看到的一切内容点赞来狂刷存在感,这种人就被称为“点赞狂魔”。他们点赞的标签非常分散,无法体现出明显的特性。本题就要求你写个程序,通过统计每个人点赞的不同标签的数量,找出前3名点赞狂魔。
输入格式:
输入在第一行给出一个正整数N(≤100),是待统计的用户数。随后N行,每行列出一位用户的点赞标签。格式为“Name
K F1⋯FK”,其中Name
是不超过8个英文小写字母的非空用户名,1≤K≤1000,Fi(i=1,⋯,K)是特性标签的编号,我们将所有特性标签从 1 到 107 编号。数字间以空格分隔。
输出格式:
统计每个人点赞的不同标签的数量,找出数量最大的前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去存,去读最后的size,然后排一波序,个数相等的,优先选择点赞数n小的。
AC代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
#include<string>
#include<set>
#define INF 0x3f3f3f3f
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define fori(x) for(int i=0;i<x;i++)
#define forj(x) for(int j=0;j<x;j++)
#define memset(x,y) memset(x,y,sizeof(x))
#define memcpy(x,y) memcpy(x,y,sizeof(y))
#define sca(x) scanf("%d", &x)
#define scas(x) scanf("%s",x)
#define sca2(x,y) scanf("%d%d",&x,&y)
#define sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define scl(x) scanf("%lld",&x)
#define scl2(x,y) scanf("%lld%lld",&x,&y)
#define scl3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define pri(x) printf("%d\n",x)
#define pri2(x,y) printf("%d %d\n",x,y)
#define pris(x) printf("%s\n",x)
#define prl(x) printf("%lld\n",x)
//#include <bits/stdc++.h>
typedef long long ll;
const int maxn=1e6+7;
const int mod=1e9+7;
const double eps=1e-8;
using namespace std;
set<int>ss;
struct node
{
char s[50];
int cnt;
int n;
}a[maxn];
bool cmp(node a,node b)
{
if(a.cnt == b.cnt)
return a.n<b.n;
return a.cnt>b.cnt;
}
int main()
{
int n;
int t;
sca(t);
rep(i,0,t)
{
ss.clear();
cin>>a[i].s;
sca(a[i].n);
rep(j,0,a[i].n)
{
int temp;
sca(temp);
ss.insert(temp);
}
a[i].cnt = ss.size();
}
sort(a,a+t,cmp);
t = min(t,3);
rep(i,0,t)
{
printf("%s%c",a[i].s,i==2?'\n':' ');
}
rep(i,t,3)
{
printf("%c%c",'-',i==2?'\n':' ');
}
return 0;
}