关闭

uva 435 Block Voting

标签: uvadp状态压缩
360人阅读 评论(0) 收藏 举报
分类:

原题:
Different types of electoral systems exist. In a block voting system the members of a party do not
vote individually as they like, but instead they must collectively accept or reject a proposal. Although a party with many votes clearly has more power than a party with few votes, the votes of a small party can nevertheless be crucial when they are needed to obtain a majority. Consider for example the following five-party system:
这里写图片描述
Coalition {A,B} has 7 + 4 = 11 votes, which is not a majority. When party C joins coalition {A,B},
however, {A,B,C} becomes a winning coalition with 7+4+2 = 13 votes. So even though C is a small
party, it can play an important role.As a measure of a party’s power in a block voting system, John F. Banzhaf III proposed to use the power index. The key idea is that a party’s power is determined by the number of minority coalitions that it can join and turn into a (winning) majority coalition. Note that the empty coalition is also a minority coalition and that a coalition only forms a majority when it has more than half of the total number of votes. In the example just given, a majority coalition must have at least 13 votes.
In an ideal system, a party’s power index is proportional to the number of members of that party.
Your task is to write a program that, given an input as shown above, computes for each party its
power index.
Input
The first line contains a single integer which equals the number of test cases that follow. Each of the following lines contains one test case.The first number on a line contains an integer P in [1 … 20] which equals the number of parties for that test case. This integer is followed by P positive integers, separated by spaces. Each of these integers represents the number of members of a party in the electoral system. The i-th number represents party number i. No electoral system has more than 1000 votes.
Output
For each test case, you must generate P lines of output, followed by one empty line. P is the number of parties for the test case in question. The i-th line (i in [1…P]) contains the sentence:
party i has power index I where I is the power index of party i.
Sample Input

3
5 7 4 2 6 6
6 12 9 7 3 1 1
3 2 1 1
Sample Output

party 1 has power index 10
party 2 has power index 2
party 3 has power index 2
party 4 has power index 6
party 5 has power index 6

party 1 has power index 18
party 2 has power index 14
party 3 has power index 14
party 4 has power index 2
party 5 has power index 2
party 6 has power index 2

party 1 has power index 3
party 2 has power index 1
party 3 has power index 1
中文:

给你n个数,现在要计算每个数的“指数”。假设这个数是a,所有的数的和是sum,那么除了a意外的所有的数进行组合,组得到的和在不超过sum/2的的情况下加上这个数a,那么a的指数就+1。如样例一里面,
7的指数是10,除了7以外,剩下的数进行组合有2^4=16种组合,其中有10种组合满足和小于13且加上7大于13。现在让你找出每个数的指数。

#include <bits/stdc++.h>
using namespace std;
int dp[1<<20+1];
int vote[21],ans[21];
int main()
{
    ios::sync_with_stdio(false);
    int n,t,tot,half;
    cin>>t;
    while(t--)
    {
        cin>>n;
        tot=0;
        memset(ans,0,sizeof(ans));
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=n;i++)
        {
            cin>>vote[i];
            tot+=vote[i];
        }
        half=(tot)/2;
        for(int s=1;s<(1<<n);s++)
        {
            for(int i=1;i<=n;i++)
            {
                if(s>>(i-1)&1)
                    dp[s]=dp[s&~(1<<(i-1))]+vote[i];
            }
        }
        for(int s=0;s<(1<<n);s++)
        {
            for(int i=1;i<=n;i++)
            {
                if(!(s>>(i-1)&1))
                {
                    if(dp[s]+vote[i]>half&&dp[s]<=half)
                        ans[i]++;
                }
            }
        }
        for(int i=1;i<=n;i++)
            cout<<"party "<<i<<" has power index "<<ans[i]<<endl;
        cout<<endl;
    }
    return 0;
}

解答:
很简单的状态压缩动态规划题目,很适合练手。一共有20个数,所以状态可以是2^20次幂个。设置dp[s]为集合s时数的和,如果集合s不超过总和的一半,且集合s当中没有第i个数。那么dp[s∪i]=dp[s]+vote[i]
其中vote[i]为第i个数是多少。

1
0
查看评论

UVA 10142 Australian Voting(模拟)

题意:澳大利亚投票系统要求选民们将所有候选人按愿意选择的程度排序,一张选票就是一个排序。一开始,每张选票的首选项将被统计。若有候选人得票超过50%,他讲直接胜出;否则,所有并列最低的候选人出局,而那些将出局候选人排在第一位的选票将被重新统计为排名最高的未出局候选人。这一筛选过程将持续进行,直到某个候...
  • LYHVOYAGE
  • LYHVOYAGE
  • 2014-07-08 17:14
  • 1281

UVa 10142 - Australian Voting

题目:澳大利亚选举,有n个候选人m个公民,每个公民对每个候选人有一个期望的优先级,             选举时,先按第一优先级分配选票,得票最少的候选人的投票,将按投票人的优先级,       ...
  • mobius_strip
  • mobius_strip
  • 2015-07-20 21:24
  • 1183

Block Voting --解题报告

    这道题做的有点狼狈,效率不高,差一点就TLE的AC了。看status里的,AC的时间大多数都是0ms的。肯定有一个更有效率的算法的。下面说下我的狼狈算法。  出处:http://acm.jlu.edu.cn/joj/showproblem.p...
  • scut_lyq00
  • scut_lyq00
  • 2009-07-01 13:05
  • 281

[翻译自mos文章] 当linux kernel和kmod-oracleasm升级之后,CRS不能发现voting disk.

[翻译自mos文章] 当linux kernel和kmod-oracleasm升级之后,CRS不能发现voting disk.
  • msdnchina
  • msdnchina
  • 2016-09-24 00:03
  • 1520

高通骁龙435(MSM8940)处理器达到什么水平

高通对其中低端的骁龙600和骁龙400系列处理器进行了一次更新,推出了三款芯片——骁龙625、骁龙435和骁龙425,三款芯片都配以更快的LTE网络基带、更高的功能以及更长的电池续航。那么骁龙435功能到达什么水平?下面小编来为我们剖析。 骁龙435选用的是28nm工艺制程,装备了八个Cortex...
  • szx940213
  • szx940213
  • 2018-01-22 15:02
  • 1154

UVa 10142 Australian Voting

#include #include #include char Candidates[20][80]; int Votes[1000][20]; void elect(int num,int voteNum) { int Eliminate[20]; int Count[20]; in...
  • holyrain
  • holyrain
  • 2014-04-14 15:56
  • 271

Moore's voting algorithm

最近在刷LeetCode的题的时候,发现一个特别巧妙的算法:Moore’s voting algorithm。 这个算法是解决这样一个问题:从一个数组中找出出现半数以上的元素。 Moore的主页上有这个算法的介绍:A Linear Time Majority Vote Algorithm和这个算...
  • chfe007
  • chfe007
  • 2015-01-20 15:57
  • 8853

Moore’s Voting Algorithm

Moore’s Voting AlgorithmMoore’s Voting Algorithm该算法是找出重复元素的最佳的算法,其时间复杂度为O(n)O(n)而空间复杂度为O(1)O(1)。
  • shinanhualiu
  • shinanhualiu
  • 2015-12-26 21:29
  • 923

显著性轮廓提取、轮廓编组综述要看的内容(三)Tensor Voting学派

Tensor Voting学派Gérard Medioni<br />这个也是大牛了,在Microsoft Academic上索引数量达到3559。<br />83年南加州大学博士毕业,现在是南加州大学计算机与工程学院教授,01-07年是南加州大学计算机学院的Cha...
  • visionfans
  • visionfans
  • 2011-03-15 22:14
  • 2140

UVA 10142 Australian Voting

Australian ballots require that the voter rank the candidates in order of choice. Initially only the first choices are counted and if one candidate re...
  • coding__girl
  • coding__girl
  • 2017-10-03 14:20
  • 81
    最新评论