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


相关推荐

  • laravel5.*安装使用Redis以及解决Class ‘Predis\Client’ not found和Fatal error: Non-static method Redis::set() c…

    laravel5.*安装使用Redis以及解决Class ‘Predis\Client’ not found和Fatal error: Non-static method Redis::set() c…

    2021年10月22日
    63
  • 根据两点经纬度计算距离

    根据两点经纬度计算距离在实际应用当中,一般是通过一个个体的编码来查找该编码对应的地区中心的经纬度,然后再根据这些经纬度来计算彼此的距离,从而估算出某些群体之间的大致距离范围(比如酒店旅客的分布范围-各个旅客的邮政编码对应的经纬度和酒店的经纬度所计算的距离范围-等等)。用GPS测出两个点的经纬度后,如何计算这两个点之间的距离呢?设两点A、B的经、纬度分别为(jA,wA)(jB,wB),则半径为

    2022年9月23日
    5
  • ubuntu下安装python3

    ubuntu下安装python3安装步骤ubuntu本身安装的时候已经自带python了,在终端输入python-V查看当前python版本python-V如上图,当前电脑安装的python版本是2.7.12下载最新的python3sudoapt-getinstallpython3如图,我的电脑本身已经装有python3了,如果没安装有,则应该安装最

    2022年6月23日
    46
  • 一个perl线程使用方法的简单演示

    一个perl线程使用方法的简单演示

    2021年8月10日
    57
  • 一篇万字博文带你入坑爬虫这条不归路 【万字图文】

    ????最近,很多粉丝私信我问——爬虫到底是什么?学习爬虫到底该从何下手?????????其实,我想说的也是曾经的我身为小白的时候某些大牛对我说过的——很多时候我们都有一颗想要学习新知识的心,却总是畏惧于对想要学习内容的无知,这也是多数人失败甚至后悔终身的:因为他们从来没有开始过!????????借一位几年前带我入坑的前辈的话——坑就在你面前,别总是犹豫徘徊,大胆一点:向前一步,入了这个坑,莽着头就是往前冲,别多想,别回头,终有一天——>你也会成为别人的前辈!????今日份鸡汤已成功送达,目

    2022年4月6日
    44
  • Cubieboard究竟几个意思?

    Cubieboard究竟几个意思?Cubieboard究竟几个意思?2013-08-1612:16张海春0条评论Cubieboard是由一支中国珠海的技术团队Cubieteam开发的一个开源MiniPC,有些类似于英国人开发的树莓派,但是在硬件的性能上,接口丰富性上和扩展性上均优于后者,同时本次创客马拉松深圳的开发板也得到了Cubieboard的赞助。Cubieboard一经推出就在全球范围内G…

    2022年7月22日
    12

发表回复

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

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