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


相关推荐

  • Anaconda 的安装教程(图文)「建议收藏」

    Anaconda的介绍Anaconda指的是一个开源的Python发行版本,其包含了conda、Python等180多个科学包及其依赖项。因为包含了大量的科学包,Anaconda的下载文件比较大。这么说可能有点抽象,大家可以直接把Anaconda理解为一个python的傻瓜捆绑包就行了Anaconda下载下载地址:https://www.anaconda.com/download/…

    2022年4月9日
    42
  • 给你的wordpress博客中加入喜欢的鼠标指针

    想给你的博客加个喜欢的鼠标指针吗?其实很简单的,wordpress中要加入只需修改皮肤中的css。在body中插入cursor:url(‘鼠标指针网址’)}就可以了,如果想修改鼠标指针接触到链接的鼠标样式,那只要在a中插入cursor:url(‘鼠标指针网址’),我用的是个企鹅,挺好玩的。我也发上来,喜欢的可以用用。鼠标指针转载于:https://www.cnblogs.com/joyp…

    2022年4月12日
    52
  • 电信光猫改桥接模式教程_千兆光猫有必要改桥接模式吗

    电信光猫改桥接模式教程_千兆光猫有必要改桥接模式吗如果只是改桥接可以试试下面这两个地址:http://192.168.1.1/bridge_route.gchhttp://192.168.1.1:8080/bridge_route.gch转载于:https://www.cnblogs.com/Devopser/p/11257535.html…

    2022年10月8日
    2
  • bit rate / frame rate /sample rate等等

    bit rate / frame rate /sample rate等等原文地址码率:Bit Rate,指视频或音频文件在单位时间内使用的数据流量,该参数的单位通常是Kbps,也就是千比特每秒。通常2000kbps~3000kbps就已经足以将画质效果表现到极致了。码率参数与视频文件最终体积大小有直接性的关系。 (编码码率—软件)  混合码率:Overall Bit Rate,指视频文件中视频和音频混合后的整体平均码率。一般描述一个视频文件的码率都是指

    2022年10月17日
    2
  • 从零到上亿用户,我是如何一步步优化MySQL数据库的?(建议收藏)[通俗易懂]

    从零到上亿用户,我是如何一步步优化MySQL数据库的?(建议收藏)[通俗易懂]冰河亲历的亿级流量下的MySQL优化实战,强烈建议收藏!!

    2022年5月22日
    40
  • 新手小白学JAVA 数组 数组工具类 二维数组

    新手小白学JAVA 数组 数组工具类 二维数组1数组1.1概念数组Array,标志是[],用于储存多个相同类型数据的集合想要获取数组中的元素值,可以通过脚标(下标)来获取数组下标是从0开始的,下标的最大值是数组的长度减11.2创建数组数组的创建方式一般分为动态初始化和静态初始化动态初始化int[]a=newint[5];静态初始化int[]b=newint[]{1,2,3,4,5};int[]c={1,2,3,4,5};1.3创建数组过程分析程序创建数组int[]a=new

    2022年5月1日
    37

发表回复

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

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