-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconclave.cpp
More file actions
65 lines (62 loc) · 1.95 KB
/
conclave.cpp
File metadata and controls
65 lines (62 loc) · 1.95 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
#include <iostream>
#include <fstream>
#include <vector>
#include "conclave.h"
#include <utility>
#include <algorithm>
using namespace std;
int main(){
ifstream in("input.txt");
ofstream out("output.txt");
int N, num_riun;
in >> N >> num_riun;
vector<pair<int,bool>> votanti(N,make_pair(-1,false));
vector<vector<int>> meetings(num_riun); // this matrix stores the ppl in the different meetings
int R_i=0;
int R_j=0;
for (int i = 0; i < num_riun; i++) {
in >> R_i;
//cout << "riunione mum: "<<i << " ,num part: " << R_i <<endl << "\t";
for (int j = 0; j < R_i; j++) {
in >> R_j;
//cout << R_j << " ";
meetings[i].push_back(R_j);
if(votanti[R_j].first==-1){
votanti[R_j].first = 1;
} else
votanti[R_j].first++;
}
//cout << endl;
}
/*for (size_t i = 0; i < votanti.size(); i++) {
cout << i << " | " << votanti[i].first << endl;
}*/
vector<int> solution;
for (size_t i = 0; i < meetings.size(); i++) {
int max_sofar = 0;
int stored_index=0;
bool skipped = false;
for (size_t j = 0; j < meetings[i].size(); j++) {
//cout << "try: "<<meetings[i][j] << "\n";
if(votanti[meetings[i][j]].second){// if a votante was already chosen then there's nothing to do for this meeting
skipped=true;
break;
}
if(votanti[meetings[i][j]].first > max_sofar){
max_sofar = votanti[meetings[i][j]].first;
stored_index = meetings[i][j];
}
}
if(!skipped){
votanti[stored_index].second = true;
solution.push_back(stored_index);
}
//cout <<endl;
}
out << solution.size() << " ";
for (size_t i = 0; i < solution.size(); i++) {
out << solution[i] << " ";
}
out << "#";
return 0;
}