-
Notifications
You must be signed in to change notification settings - Fork 0
/
10142.cpp
95 lines (94 loc) · 1.54 KB
/
10142.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cctype>
using namespace std;
int vote[1001][21];
int number;
char name[21][100];
int max(int *a,bool *b,int *maxlt)
{
int max=0;
for (int i=1;i<=number;i++)
if (b[i] && a[i]>max) {max=a[i];*maxlt=i;}
return max;
}
int min(int *a,bool *b)
{
int min=1001;
for (int i=1;i<=number;i++)
if (b[i] && a[i]<min) min=a[i];
return min;
}
void fuck(int k)
{
int point[1001];
int member[21];
bool lose[21];
memset(point,0,sizeof(point));
memset(member,0,sizeof(member));
memset(lose,true,sizeof(lose));
int maxlt,maxv,minv;
while (1)
{
for (int i=0;i<k;i++)
{
while (!lose[vote[i][point[i]]])
point[i]++;
member[vote[i][point[i]]]++;
}
if ((maxv=max(member,lose,&maxlt))==(minv=min(member,lose)))
{
for (int i=1;i<=number;i++)
if (lose[i]) cout<<name[i]<<endl;
return ;
}
else if (maxv*2>k)
{
cout<<name[maxlt]<<endl;
return ;
}
else
{
for (int i=1;i<=number;i++)
if (lose[i] && minv==member[i]) lose[i]=false;
}
memset(member,0,sizeof(member));
}
}
main()
{
char temp[10];
int total;
char c;
//freopen("data.txt","r",stdin);
cin>>total;
getchar();
getchar();
while (total--)
{
cin>>number;
getchar();
for (int i=1;i<=number;i++)
{
gets(name[i]);
}
int k=0;
while ((c=getchar())!=EOF)
{
if (isdigit(c))
{
ungetc(c,stdin);
for (int i=0;i<number;i++)
scanf("%d",&vote[k][i]);
k++;
getchar();
}
else if (c=='\n')
break;
}
fuck(k);
if (total) cout<<endl;
}
return 0;
}