-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path435-Block Voting.cpp
37 lines (35 loc) · 973 Bytes
/
435-Block Voting.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
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t,p,v;
cin >> t;
while(t--) {
cin >> p;
vector<int> parties;
int total = 0;
for(int i=0;i<p;i++) {
cin >> v;
parties.push_back(v);
total += v;
}
total /= 2;
// foreach party, compute power index
for(int i=0;i<p;i++) {
int pIdx = 0;
// foreach coliation combination
for(int j=0;j<(1<<p);j++){
// not a member of coliation
if(!(1<<i & j)){
int curMembers = 0;
for(int k=0;k<p;k++)
if(1<<k & j) curMembers += parties[k];
if(curMembers <= total && curMembers+parties[i] > total )
pIdx++;
}
}
printf("party %d has power index %d\n",i+1,pIdx);
}
cout << endl;
}
}