Advertisement
royalsflush

Referência para UVa 435 (Luiza)

Apr 6th, 2012
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int p;
  5. int v[25];
  6. int wins[25];
  7. int tot;
  8. int _42;
  9.  
  10. int main() {
  11.     scanf("%d", &_42);
  12.    
  13.     while (_42--) {
  14.         scanf("%d", &p);
  15.         tot=0;     
  16.  
  17.         for (int i=0; i<p; i++)
  18.             scanf("%d", &v[i]);
  19.         for (int i=0; i<p; i++)
  20.             tot+=v[i];
  21.  
  22.         memset(wins,0,sizeof(wins));
  23.  
  24.         for (int i=0; i<(1<<p); i++) {
  25.             int votes=0;
  26.  
  27.             for (int j=0; j<p; j++)
  28.                 if (i&(1<<j)) votes+=v[j];
  29.  
  30.             if (tot>=2*votes) continue;
  31.  
  32.             for (int j=0; j<p; j++)
  33.                 if (i&(1<<j) && tot>=2*(votes-v[j]))
  34.                     wins[j]++;
  35.         }
  36.  
  37.         for (int i=0; i<p; i++)
  38.             printf("party %d has power index %d\n", i+1,wins[i]);
  39.         printf("\n");
  40.     }
  41.    
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement