Background
In one of the countries of Caribbean basin all decisions were accepted by the simple majority of votes at the general meeting of citizens (fortunately, there were no lots of them). One of the local
parties, aspiring to come to power as lawfully as possible, got its way in putting into effect some reform of the election system. The main argument was that the population of the island recently had increased and it was to longer easy to hold general meetings.
The essence of the reform is as follows. From the moment of its coming into effect all the citizens were divided into K (may be not equal) groups. Votes on every question were to be held then in each
group, moreover, the group was said to vote “for” if more than half of the group had voted “for”, otherwise it was said to vote “against”. After the voting in each group a number of group that had voted “for” and “against” was calculated. The answer to the
question was positive if the number of groups that had voted “for” was greater than the half of the general number of groups.
At first the inhabitants of the island accepted this system with pleasure. But when the first delights dispersed, some negative properties became obvious. It appeared that supporters of the party, that
had introduced this system, could influence upon formation of groups of voters. Due to this they had an opportunity to put into effect some decisions without a majority of voters “for” it.
Let’s consider three groups of voters, containing 5, 5 and 7 persons, respectively. Then it is enough for the party to have only three supporters in each of the first two groups. So it would be able
to put into effect a decision with the help of only six votes “for” instead of nine, that would be necessary in the case of general votes.
Problem
You are to write a program, which would determine according to the given partition of the electors the minimal number of supporters of the party, sufficient for putting into effect of any decision,
with some distribution of those supporters among the groups.
Input
In the first line an only odd integerK— a quantity of groups — is written (1 ≤K≤ 101). In the second line there are writtenKodd integers, separated with a space. Those
numbers define a number of voters in each group. The population of the island does not exceeds 9999 persons.
Output
You should write a minimal quantity of supporters of the party, that can put into effect any decision.
Sample
| input | output |
|---|---|
3 5 7 5 |
6 |
有两个思路:
1 先排序,然后从最小的值中取半数+1的值,就得到解了
2 使用priority_queue,就可以不排序,直接大数出列,小数入列,也可以很容易解决。
两个思路的时间效率都是O(n),但是运行起来应该是第二个思路比较快点。
这里使用priority_queue来解题。
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
void DemocracyInDanger1025()
{
int k = 0, ans = 0, a = 0;
cin>>k;
priority_queue<int> pqu;
int i = 0;
for ( ; i <= (k>>1); i++)
{
cin>>a;
a = (a>>1) + 1;
pqu.push(a);
ans += a;
}
for ( ; i < k; i++)
{
cin>>a;
a = (a>>1) + 1;
if (a < pqu.top())
{
ans -= pqu.top() - a;
pqu.pop();
pqu.push(a);
}
}
cout<<ans;
}
int main()
{
DemocracyInDanger1025();
return 0;
}
探讨了加勒比盆地某国投票系统改革,引入群体表决机制以应对人口增长及会议频率增加的问题。分析了该系统如何被引入的政党利用,通过在不同群体内分配支持者数量,影响决策过程,实现少于简单多数的支持票就能通过决议的效果。本文提出了一种计算所需最小支持者数量的方法,以防止此类操纵,并确保任何决策都能获得足够的公众支持。
189

被折叠的 条评论
为什么被折叠?



