POJ2370 Democracy in danger

题目超级水,但题目意思不好理解(英语太差。。。),排个序,然后答案就出来了。

Democracy in danger

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3136   Accepted: 2311

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

Ural State University Internal Contest October‘2000 Junior Session

 1 //oimonster
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<iostream>
 5 using namespace std;
 6 int a[10001];
 7 void qsort(int s[], int l, int r)
 8 {
 9     int t;
10     int i = l, j = r, x = s[(i+j)/2];
11     do
12     {
13         while(x>s[i])
14             i++;
15         while(x<s[j])
16             j--;
17         if(i <= j){
18             t=s[i];
19             s[i]=s[j];
20             s[j]=t;
21             i++;
22             j--;
23         }
24     }while (i<j);
25     if (l<j)
26        qsort(s,l,j);
27     if (i<r)
28        qsort(s,i,r);
29 }
30 int main(){
31     int i,j,n;
32     scanf("%d",&n);
33     for(i=1;i<=n;i++){
34         scanf("%d",&a[i]);
35     }
36     qsort(a,1,n);
37     int ans=0;
38     for(i=1;i<=(n+1)/2;i++){
39         ans+=(a[i]+1)/2;
40     }
41     printf("%d\n",ans);
42     return 0;
43 }

时间: 2024-08-02 02:51:19

POJ2370 Democracy in danger的相关文章

POJ 2370 Democracy in danger(简单贪心)

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 citize

URAL 1025. Democracy in Danger (贪心)

1025. Democracy in Danger Time limit: 1.0 second Memory limit: 64 MB 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

11 URAL1025 Democracy in Danger

选择人数较少的m/2只队,每只队中半数人投票. #include<cstdio> #include<algorithm> using namespace std; int main() { int i,n,ans,s[110]; while(~scanf("%d",&n)) { for(i=0;i<n;i++) scanf("%d",&s[i]); sort(s,s+n); ans=0; for(i=0;i<=n/

URAL 1025 Democracy in Danger

排个序 1 import java.util.Arrays; 2 import java.util.Scanner; 3 4 public class P1025 5 { 6 public static void main(String args[]) 7 { 8 try (Scanner cin = new Scanner(System.in)) 9 { 10 while (cin.hasNext()) 11 { 12 int n = cin.nextInt(); 13 int a[] = n

poj 2370 Democracy in danger

题目链接:http://poj.org/problem?id=2370 题意:大意好像是类似选举,给出K,表示一共K组,然后给出K组人每组的人数,都是奇数.每组人有超过一半的人同意就认为那一组人同意,有超过半数的组同意就决定通过,看最少要多少人同意能决定通过. 分析:贪心.(水)将每组人数按照从小到大排序,选择前面(k)/2+1组人每组a[i]/2+1的人同意就好. 代码: #include<cstdio> #include<cmath> #include<cstring&g

北大ACM题库习题分类与简介(转载)

在百度文库上找到的,不知是哪位大牛整理的,真的很不错! zz题 目分类 Posted by fishhead at 2007-01-13 12:44:58.0 -------------------------------------------------------------------------------- acm.pku.edu.cn 1. 排序 1423, 1694, 1723, 1727, 1763, 1788, 1828, 1838, 1840, 2201, 2376, 23

ACM训练方案-POJ题目分类

ACM训练方案-POJ题目分类 博客分类: 算法 ACM online Judge 中国: 浙江大学(ZJU):http://acm.zju.edu.cn/ 北京大学(PKU):http://acm.pku.edu.cn/JudgeOnline/ 杭州电子科技大学(HDU):http://acm.hdu.edu.cn/ 中国科技大学(USTC):http://acm.ustc.edu.cn/ 北京航天航空大学(BUAA)http://acm.buaa.edu.cn/oj/index.php 南京

转载:poj题目分类(侵删)

转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K–0.50K:中短代码:0.51K–1.00K:中等代码量:1.01K–2.00K:长代码:2.01K以上. 短:1147.1163.1922.2211.2215.2229.2232.2234.2242.2245.2262.2301.2309.2313.2334.2346.2348

转载 ACM训练计划

leetcode代码 利用堆栈:http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/http://oj.leetcode.com/problems/longest-valid-parentheses/ (也可以用一维数组,贪心)http://oj.leetcode.com/problems/valid-parentheses/http://oj.leetcode.com/problems/largest-rectang