POJ 2370 Democracy in danger(简单贪心)

简介: Democracy in danger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3388   Accepted: 2508 Description In one of the...
Democracy in danger
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3388   Accepted: 2508

Description

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.
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

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

Output

You should write an only natural number — a minimal quantity of supporters of the party, that can put into effect any decision.

Sample Input

3
5 7 5

Sample Output

6

Source

题目链接:http://poj.org/problem?id=2370
题解:以前挂的一些贪心的题没有做,有位大佬叫我写下题解,有些看不懂题意,我恭敬不如从命了,写点吧,算是复习下贪心吧!
题目大意是关于投票,已知k个组,这k个组中只要有一半以上通过了,就算通过了所以取k/2+1;要想去最少的通过人数,就想办法使得这k/2+1这些组的人数都是最少的,这时可以进行排序,然后取前k/2+1个组;每个组中只要有一半以上的人通过了,就算通过了,所以只要这些k/2+1组的每组超过一半的人通过了,就通过了;及a/2+1,a为每组的人数!
下面给出AC代码:
 1 #include <iostream>
 2 #include <cstring>
 3 #include <algorithm>
 4 #include <cstdio>
 5 using namespace std;
 6 int main()
 7 {
 8     int a[110];
 9     int n;
10     while(scanf("%d",&n)!=EOF)
11     {
12         for(int i=0;i<n;i++)
13             scanf("%d",&a[i]);
14         sort(a,a+n);
15         int sum=0;
16         for(int i=0;i<n/2+1;i++)
17             sum+=a[i]/2+1;
18             printf("%d\n",sum);
19     }
20     return 0;
21 }

 

目录
相关文章
|
人工智能 网络架构
|
算法
POJ 3154 Graveyard【多解,数论,贪心】
Graveyard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1707   Accepted: 860   Special Judge Description Prog...
1207 0
poj supermaket (贪心)
http://poj.org/problem?id=1456 #include #include #include using namespace std; struct nod { int a; int d; }; bool cmp(nod x,nod y) { return x.
673 0
|
文件存储
poj 2229 Sumsets 【动态规划】
点击打开题目 Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 13291   Accepted: 5324 Description Far...
907 0
|
机器学习/深度学习
【OJ】贪心法 Saruman's Army POJ 3069 /acmclub 12132
题目链接:点击打开链接 /* 6 10 贪心法Saruman's Army POJ 3069 1 7 15 20 30 50 ans=3 */ #include #include using namespace std; int x[1010]; ...
863 0
|
机器学习/深度学习
【OJ】贪心法 Saruman&#39;s Army POJ 3069 /acmclub 12132
题目链接:点击打开链接 /* 6 10 贪心法Saruman's Army POJ 3069 1 7 15 20 30 50 ans=3 */ #include #include using namespace std; int x[1010]; int main(){ // freopen("贪心法 Saruman's Army poj3069.
820 0
poj Dollar Dayz(完全背包)
点击打开链接poj 3181 思路: 完全背包+高精度 分析: 1 题目是裸的完全背包,但是要注意的一个地方是要用高精度 代码: #include #include #include #include using namespa...
951 0