C: IOI 2017 Logo
时间限制: 1 Sec 内存限制: 128 MB
提交: 111 解决: 42
[提交] [状态] [讨论版] [命题人:admin]
题目描述
Iran is the host of the International Olympiad in Informatics (IOI) 2017. In order to design the IOI 2017 logo, the organizing committee of the IOI 2017 decided to publicly call for logos. It was not surprising that many logos were received in a short time as the young generation in Iran is actively taking part in any national event. In the first round, logos were judged by some professional graphic designers, and the best logos being artistically capable to be the IOI 2017 logo were selected to be judged in the second round.
The selected logos are now presented to the organizing-committee members for voting. The voting system is a little bit complicated: each member can vote for at most three different logos in some order. The first, second and third choices of each member are awarded 3, 2 and 1 points, respectively. The score of a logo is the total points the logo receives from all members. The logo with the highest score is the winner. In the case of ties, the winner is the logo with higher number of first votes. Again, if some logos have the same score and first votes, the logo with more second votes is the winner. If we still have ties, all of them would be winners. Given the voting information, your job is to identify the winner logo (or logos).
输入
There are multiple test cases in the input. The first line of each test case contains a positive integer n denoting the number of voters (1 ⩽ n ⩽ 100). Each of the next n lines starts with an integer di , representing the number of logos chosen by the i-th voter (1 ⩽ di ⩽ 3), followed by di different logo IDs showing the choices of that voter (from left to right). Each logo Idis a positive integer not exceeding 106 . All integers in a line are separated with a single space. The input terminates with a line containing 0 which should not be processed.
输出
For each test case, output a line containing the winner logos in the increasing order of their IDs. Logo IDs in a line must be separated with a single space.
样例输入
4
3 5 2 1
3 12 5 2
2 1 2
3 2 1 5
2
3 3 2 1
3 2 3 1
0
样例输出
2
2 3
开始并没有在意最后输出的顺序,题目里也没有提,就以为是按照原来的顺序输出了,结果wa了一发
后来一想,这题没有sj,可能是要从小到大输出吧,然后就emmm、A了。。。
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct Point{
int self;
int cn[3];
int cc;
bool operator < (const Point &a) const{
if(cc!=a.cc)
return cc>a.cc;
if(cn[2]!=a.cn[2])
return cn[2]>a.cn[2];
if(cn[1]!=a.cn[1])
return cn[1]>a.cn[1];
return self<a.self;///就这里了qwq
}
}P[105];
int vis[1000006];
int main(){
int n,m,t,cnt;
while(~scanf("%d",&n) && n)
{
cnt = 1;
for(int i=0;i<n;i++)
{
scanf("%d",&m);
for(int j=0;j<m;j++)
{
scanf("%d",&t);
if(!vis[t])
{
P[cnt].self = t,vis[t] = cnt++;
for(int k=2;k+1;k--)
P[cnt-1].cn[k]=0;
P[cnt-1].cc=0;
}
int k = vis[t];
P[k].cn[2-j]++;
}
}
for(int i=1;i<cnt;i++)
P[i].cc = 3*P[i].cn[2]+2*P[i].cn[1]+P[i].cn[0];
sort(P+1,P+1+cnt);
printf("%d",P[1].self);
int k = 2;
while(k<cnt && P[k].cc == P[1].cc && P[k].cn[2]==P[1].cn[2] && P[k].cn[1]==P[1].cn[1] )
printf(" %d",P[k++].self);
printf("\n");
memset(vis,0,sizeof(vis));
memset(P,0,sizeof(P));
}
return 0;
}