-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPRESIDEN.cpp
More file actions
79 lines (71 loc) · 2.07 KB
/
PRESIDEN.cpp
File metadata and controls
79 lines (71 loc) · 2.07 KB
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
/* http://www.spoj.com/problems/PRESIDEN/ */
#include<stdio.h>
#include<list>
#include<map>
using namespace std;
const int MAX=110;
list<int> myList[MAX];
int main()
{
//freopen("PRESIDEN.in","r",stdin);
map<int,float> myMap;
map<int,float>::iterator it;
int T,C,V,preference,firstP,secondP;
double percentage;
scanf("%d",&T);
for(int i=0;i<T;i++){
scanf("%d",&C);
scanf("%d",&V);
for(int j=0;j<V;j++){
for(int k=0;k<C;k++){
scanf("%d",&preference);
if(k==0){
percentage=(1/(float)V)*100.00;
myMap[preference]=myMap[preference]+percentage;
}
myList[j].push_back(preference);
}
}
percentage=0;
for(it=myMap.begin();it!=myMap.end();it++){
if(it->second>percentage){
firstP=it->first;
percentage=it->second;
}
}
if(percentage>50.00){
printf("%d 1\n",firstP);
}else{
it=myMap.find(firstP);
myMap.erase(it);
percentage=0;
for(it=myMap.begin();it!=myMap.end();it++){
if(it->second>percentage){
secondP=it->first;
percentage=it->second;
}
}
myMap.clear();
for(int h=0;h<V;h++){
for (list<int>::iterator itl=myList[h].begin(); itl != myList[h].end(); ++itl){
if((*itl)==firstP || (*itl)==secondP){
myMap[*itl]++;
break;
}
}
}
percentage=0;
for(it=myMap.begin();it!=myMap.end();it++){
if(it->second > percentage){
firstP=it->first;
percentage=it->second;
}
}
printf("%d 2\n",firstP);
}
for(int h=0;h<110;h++) myList[h].clear();
myMap.clear();
}
//fclose(stdin);
return 0;
}