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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • UE4摄像机_ue4怎么做摄像机动画

    UE4摄像机_ue4怎么做摄像机动画一.摄像机工作原理在游戏中,摄像机是玩家的眼睛,他控制了玩家的视点(POV即PointOfView,后面简称POV)位置以及玩家的视野大小(FOV即FieldOfView,后面简称FOV)。一句话,摄像机决定了我们去观察这个游戏世界。游戏的类型多种多样,有第一人称的FPS游戏,有第三人称的动作游戏,还有需要统筹全局来观察的RTS游戏。简单来说,第一人称就是把POV放在人眼睛的位置,第三人称就是把P…

    2022年10月4日
    4
  • pki密码技术_PKI体系管理

    pki密码技术_PKI体系管理HTTPS的诞生可先参考网络协议、HTTPS协议等文章明文传输对称加密“加密”和“解密”使用【相同的】密钥,如果密钥可以安全的传输,那么消息也应该可以安全的传输。非对称加密上述非对称加密与对称加密效果基本一样,如果公钥可以安全的传输,那么消息也应该可以安全的传输,接下来看看被劫持的情况。窃听者可以伪造服务器的公钥与客户端通讯,客户端以为是跟服务器通讯,其实是与窃听者在通讯。无论是对称加密还是非对称加密,都遗留了一个问题没有解决,那就是如何证明我们访问的网站就是我们

    2022年8月22日
    5
  • 手机python 3.8解释器_Python 3.8 解释器安装教程

    手机python 3.8解释器_Python 3.8 解释器安装教程Python是一个门面向对象的解释型编程语言,如果要完成Python程序的开发,需要有Python解释器的支持,所以首先需要配置好Python解释器(本教程选择最新的Python3.8.3版本),没有安装的小伙伴,可以跟着一起操作哦。一、软件的下载1、下载【Python解释器】。官方网址为:www.python.org2、选择【Windows】系统,点击【Python3.8.3】,其中【V…

    2022年7月22日
    56
  • 阈值分割法简述 – ywywcy的专栏 – CSDNBlog

    阈值分割法简述 – ywywcy的专栏 – CSDNBlog阈值分割法阈值分割法分为全局阈值法和局部阈值分割法 所谓局部阈值分割法是将原始图像划分成较小的图像 并对每个子图像选取相应的阈值 在阈值分割后 相邻子图像之间的边界处可能产生灰度级的不连续性 因此需用平滑技术进行排除 局部阈值法常用的方法有灰度差直方图法 微分直方图法 局部阈值分割法虽然能改善分割效果 但存在几个缺点 1 每幅子图像的尺寸不能太小 否则统计出的结果无意义

    2025年8月11日
    0
  • batchnorm解读

    batchnorm解读转自:https://blog.csdn.net/qq_25737169/article/details/79048516目录第一节:Batchnorm主要解决的问题1.1InternalCovariateShift1.2covariateshift第二节:Batchnorm原理解读第三节:Batchnorm源码解读第四节:Batchnorm的优…

    2022年6月3日
    44

发表回复

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

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