Ural 1025-Democrary in Danger

Ural 1025-Democrary in Danger

问题描述】

    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 integer K — a quantity of groups — is written (1 ≤ K ≤ 101). In the second line there are written K odd 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 26224745_mhbm.gif

3
5 7 5

    Sample Output

6

【解题思路

    人数最少的前(n/2)+1组中,每组取半数求和即为所求。


【具体实现

#include<iostream> #include<algorithm>  #define maxNum 102 using namespace std; int groupNum; int perNum[maxNum]; int main() { while (cin >> groupNum && 0<groupNum && groupNum<maxNum){ for (int i = 0; i < groupNum; i++)  cin >> perNum[i]; /*按各组人数从小到大排序*/ sort(perNum, perNum + groupNum); /*排序后一半以上各组,每组一半以上人员同意即可*/ int ans = 0; for (int i = 0; i<(groupNum + 2) / 2; ++i) ans += (perNum[i] + 2) / 2; cout << ans << endl; } return 0; }

【额外补充

    恩,就是这样。



转载于:https://my.oschina.net/CoderBleak/blog/666713

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/109053.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • pycharm 激活码 2022_通用破解码「建议收藏」

    pycharm 激活码 2022_通用破解码,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月16日
    2.0K
  • opencv 滤波 方框滤波 均值滤波 高斯滤波 中值滤波 双边滤波[通俗易懂]

    文章目录一.线性滤波1.1.方框滤波demo1.2.均值滤波demo1.3.高斯滤波demo二.非线性滤波2.1.中值滤波demo2.2.双边滤波demo结构体参考一.线性滤波1.1.方框滤波方框滤波是所有滤波器中最简单的一种滤波方式。每一个输出像素的是内核邻域像素值的平均值得到。通用的滤波kernel如下:这里是一个长宽分别为Kwidth和Kheight的窗口函数,在此区域内邻域中像素值叠加求平均即可求出位于kernel中心点像素的像素值。/**@brief使用框过滤

    2022年4月9日
    33
  • 谓词表示法表示猴子摘香蕉_猴子妈妈有14个香蕉

    谓词表示法表示猴子摘香蕉_猴子妈妈有14个香蕉案例:我们要实现以下步骤:这个案例共有以下几种情况,猴子香蕉箱子在同一处,猴子香蕉在同一处,香蕉箱子在同一出,还有三者均不在同一处,但不论是哪种情况,我们需要清楚一点就算是香蕉和猴子在同一位置,猴子也无法直接获得香蕉,因此我们第一步必须需要先找到箱子,然后再去搬着箱子移动到香蕉处。本案例中有以下四个谓词逻辑: Run(monkey,box)代表猴子去搬箱子 Getbox(monkey,box)代表猴子得到了箱子 Run(monkey,banana)代表了.

    2022年9月26日
    2
  • MySQL中tinytext、text、mediumtext和longtext详解

    MySQL中tinytext、text、mediumtext和longtext详解一、字符串类型 类型 范围 说明 Char(N)[binary] N=1~255个字节(4.1以下版本) N=1~65535个字节(4.1以下版本) binary:分辨大小写 固定长度 std_namecahr(32)notnull VarChar(N)…

    2022年4月30日
    216
  • 常量和常量表达式_里伯德常量

    常量和常量表达式_里伯德常量常量和常量表达式 long型常量以L或者l结尾,有时候,如果一个整数太大无法用int表达,也被当做long型; 无符号常量以U或者u结尾,unsignedlong型常量以UL或者ul结尾; 没有后缀的浮点数常量为double型; 有后缀F或者f的浮点数常量是float型,后缀L或者l表示longdouble型常量; 八进制和十六进制的常量也可以使用L和U后缀;

    2022年9月29日
    2
  • JVM之 方法区、永久代(PermGen space)、元空间(Metaspace)三者的区别

    JVM之 方法区、永久代(PermGen space)、元空间(Metaspace)三者的区别文章目录0、前言(JVM运行时区域)1、PermGen(永久代)2、Metaspace(元空间)3、总结0、前言(JVM运行时区域)阅读此文章时,必须已经了解了jvm运行时数据区域。 根据JVM规范,JVM运行时区域大致分为方法区、堆、虚拟机栈、本地方法栈、程序计数器五个部分。1)、方法区方法区是JVM所有线程共享。主要用于存储类的信息、常量池、方法数据、方法代码等…

    2025年5月27日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号