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

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • 2014年度总结

    2014年度总结2015都过了近1个月了,早该好好总结一下了。   2014年,对我来说,意味着忙乱、匆促、迷惑、徘徊,还有最准确的表达:抉择!   还是老规矩,分别从生活、工作、学习三个维度来回顾。  【生活篇】   (1)陪伴妻儿     看着儿子一天天长大,仿佛每一天都有新的变化:从可以走路,到能说完整的句子,每一个关键事件,都让我和老婆欣喜不已!当

  • 5G学习笔记:NSA和SA

    5G学习笔记:NSA和SA大家好,我是小枣君。第一个5G正式标准马上就要发布了,相信大家一定都在翘首企盼。之前我曾经和大家介绍过,去年12月份的时候,我们其实已经发布了“半个”5G标准。是的没错,那个时候是“非独立组网(NSA)”的5G标准。而我们现在正在等的,是“独立组网(SA)”的5G标准。关于非独立组网和独立组网,NSA和SA,虽然大家都听了很多次,但很少有人能真正搞懂它们到底是怎么…

    2022年10月25日
  • windows服务器审计日志存放位置,windows服务器审计日志存放位置[通俗易懂]

    windows服务器审计日志存放位置,windows服务器审计日志存放位置[通俗易懂]windows服务器审计日志存放位置内容精选换一换Manager的审计日志默认保存在数据库中,如果长期保留可能引起数据目录的磁盘空间不足问题,管理员如果需要将审计日志保存到其他归档服务器,可以在FusionInsightManager设置转储参数及时自动转储,便于管理审计日志信息。若用户未配置审计日志转储,当审计日志达到十万条,系统自动将这十万条审计日志保存到文件中。保存路径为主管理节为加强对…

  • 使用python进行方差分析_python多因素方差分析

    使用python进行方差分析_python多因素方差分析利用python实现方差分析简介 方差分析是一种常用的对数据进行分析的方法,用于两个及两个以上样本均数和方差差别的显著性检验。本文介绍单因素方差分析和双因素方差分析。 方差分析存在三个假设: 1、各样本总体服从正态分布。 2、各样本总体方差一样。 3、各样本总体相互独立。单因素方差分析 单因素方差分析就是在只有一种影响因素下判断各个样本间的均值差别的显著性。 数据会…

    2022年10月15日
  • hd2012 素数题

    hd2012 素数题

  • centos安装教程详解_ensp详细安装步骤

    centos安装教程详解_ensp详细安装步骤Linux中三大主流操作系统Ubuntu优点:用户界面友好、工具完善缺点:vps(虚拟服务器)成本较高、不具备商业化服务器操作系统Centos–目前常用centos6.x,centos7.x

发表回复

您的电子邮箱地址不会被公开。

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