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


相关推荐

  • log4j2配置文件详解_log4j升级到log4j2

    log4j2配置文件详解_log4j升级到log4j2Log4j的配置文件用来设置记录器的级别、输出目的地和布局,可以是log4j.properties或log4j.xml。以下讲解以log4j.properties的配置方式进行。配置文件的基本格式基本格式如下:#配置根Loggerlog4j.rootLogger=[level],appenderName1,appenderName2,……#配置日志信息输出目的地(Appe…

    2022年9月30日
    0
  • volatile禁止指令重排的原理_警告禁止指令提示颜色顺序

    volatile禁止指令重排的原理_警告禁止指令提示颜色顺序Volatile禁止指令重排什么是指令重排?你写的程序,计算机并不是按照你写的那样去执行的。源代码->编译器优化的重排->指令并行可能会重排->内存系统可能会重排->执行处理器在进行指令重排的时候,考虑,数据之间的依赖性!指令重排不会造成影响的例子intx=1;//1inty=2;//2x=x+5;//3y=x*x;//4我们所期望的:1234执行的时候可能会变成21341324但是不可能是4321

    2022年10月17日
    0
  • 机械振动单位_机械振幅单位

    机械振动单位_机械振幅单位振动一般可以用以下三个单位表示:mm、mm/s、mm/(s^2)。mm振动位移:一般用于低转速机械的振动评定;7丝就是70um,是振动位移值。mm/s振动速度:一般用于中速转动机械的振动评定;一

    2022年8月6日
    3
  • JPA语法大全 特别是JPA的不等于[通俗易懂]

    JPA语法大全 特别是JPA的不等于[通俗易懂]JPA语法大全(特别是JPA的!=不等于)Keyword:为关键词Sample:为直接用在方法名上的例子JPQLsnipper:为JPQL,@Query的写法的例子

    2022年8月31日
    2
  • linux下搭建kafka集群,linux系统zk+Kafka集群搭建

    linux下搭建kafka集群,linux系统zk+Kafka集群搭建Kafka集群搭建与配置准备工作安装java环境搭建zookeeper集群搭建kafka集群1.准备工作1.1安装包1.2准备至少3台主机(ubuntu系统)如果没有物理机,也可以弄3台虚拟机。ubuntu系统不会安装的话可以自己百度哦,这里就不细说了。作者用的是虚拟机,下面是3台电脑的配置主机名IP地址硬件配置kafka-1192.168.1.424CPU、4G内存、128G存储kafka…

    2022年4月29日
    45
  • Python语言有哪些数据类型「建议收藏」

    Python语言有哪些数据类型「建议收藏」在Python中,能够直接处理的数据类型有以下几种:一、整数Python可以处理任意大小的整数,当然包括负整数,在Python程序中,整数的表示方法和数学上的写法一模一样,例如:1,…

    2022年5月28日
    28

发表回复

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

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