1poj2370(贪心水)

来源:互联网 发布:win10关闭软件快捷键 编辑:程序博客网 时间:2024/05/21 21:37

http://poj.org/problem?id=2370

Democracy in danger
Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 2679Accepted: 1970

Description

In one of the countries ofCaribbean basin all decisions were accepted by the simple majorityof votes at the general meeting of citizens (fortunately, therewere no lots of them). One of the local parties, aspiring to cometo power as lawfully as possible, got its way in putting intoeffect some reform of the election system. The main argument wasthat the population of the island recently had increased and it wasto longer easy to hold general meetings.
The essence of the reform is as follows. From the moment of itscoming into effect all the citizens were divided into K (may be notequal) groups. Votes on every question were to be held then in eachgroup, moreover, the group was said to vote "for" if more than halfof the group had voted "for", otherwise it was said to vote"against". After the voting in each group a number of group thathad voted "for" and "against" was calculated. The answer to thequestion 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 withpleasure. But when the first delights dispersed, some negativeproperties became obvious. It appeared that supporters of theparty, that had introduced this system, could influence uponformation of groups of voters. Due to this they had an opportunityto put into effect some decisions without a majority of voters"for" it.
Let's consider three groups of voters, containing 5, 5 and 7persons, respectively. Then it is enough for the party to have onlythree supporters in each of the first two groups. So it would beable to put into effect a decision with the help of only six votes"for" instead of nine, that would .be necessary in the case ofgeneral votes.
You are to write a program, which would determine according to thegiven partition of the electors the minimal number of supporters ofthe party, sufficient for putting into effect of any decision, withsome distribution of those supporters among the groups.

Input

The input of this problemcontains two lines. In the first line an only natural number K<= 101 — a quantity of groups — is written. In thesecond line there are written K natural numbers, separated with aspace. Those numbers define a number of voters in each group. Inorder to simplify the notion of "the majority of votes" we'll saythat the number of groups also as the number of voters in eachgroup is odd. You may also consider, that the population of theisland does not exceeds 10001 persons.

Output

You should write an only naturalnumber — a minimal quantity of supporters of the party, that canput into effect any decision.

Sample Input

35 7 5

Sample Output

6

Source

Ural State University Internal Contest October'2000 JuniorSession

题意:都了好几啊。。表示看不懂。。

//K组人,超过半数组同意时就能被选举上,而通过这组的条件就是有这组有半数人以上通过
//注意输入全部都是奇数。。
#include<iostream>
#include<algorithm>
using namespace std;
int a[10001];
int main()
{
 int k;
 while(scanf("%d",&k)!=EOF)
 {
  int i;
  for(i=0;i<k;i++)
   scanf("%d",&a[i]);
  sort(a,a+k);
  int sum=0;
  for(i=0;i<k/2+1;i++)
   sum+=a[i]/2+1;
  printf("%d\n",sum);
 }
 return 0;
}

原创粉丝点击