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


相关推荐

  • 成功鲜有偶然:一览IT名人的教育成长经历

    成功鲜有偶然:一览IT名人的教育成长经历由于篇幅有限,只列举受公共认知度较高的创始人(百度百科对应人物词条被顶超过1000次)国内三强:李彦宏(百度创始人):本科就读于北京大学,硕士就读于布法罗纽约州立大学。曾任Infoseek工程师。马云(阿里巴巴创始人):本科就读于杭州师范学院。马化腾(腾讯创始人):本科就读于深圳大学。大三门户网站:王志东(新浪创始人):本科就读于北京大学,点击科技创始人。丁磊(网易创始人):本科就读于电子科

    2022年8月30日
    4
  • ntp时间同步端口_网络客户端协议没有了

    ntp时间同步端口_网络客户端协议没有了用Java实现的一个简单的NTP客户端

    2022年10月9日
    4
  • table文字水平垂直居中

    table文字水平垂直居中lt table gt nbsp nbsp lt tr gt nbsp nbsp nbsp nbsp lt tdstyle text align center vertical align middle gt nbsp nbsp nbsp nbsp nbsp nbsp 文字内容 nbsp nbsp nbsp nbsp nbsp nbsp text align center 设置水平居中 nbsp nbsp nbsp nbsp nbsp nbsp vertical align middle 设置垂直居中 nbsp nbsp nbsp nbsp

    2025年12月14日
    5
  • MySQL JDBC URL各参数详解

    MySQL JDBC URL各参数详解参数名称参数说明缺省值最低版本要求user数据库用户名(用于连接数据库)password用户密码(用于连接数据库)useUnicode是否使用Unicode字符集,如果参数characterEncoding设置为gb2312或gbk,本参数值必须设置为truefalse1.1guseSSLMySQL在高版本需要指明是否进行SSL连接在mysql连接字符串url中加入ssl=true或者false即可characterEncoding…

    2022年7月16日
    14
  • 网页设计css导航链接怎么做,如何用DIV+CSS制作导航条

    网页设计css导航链接怎么做,如何用DIV+CSS制作导航条一个蓝色主题的导航条布局案例,本CSS小实例,采用DIVCSS实现。同时不用图片做背景,直接使用背景色实现,鼠标经过悬停对应栏目名称是对应背景蓝色变深。一般导航条采用ulli列表布局,这里也不例外DIVCSS5实例也采用列表标签ulli+CSS布局。这样的导航条有以下二部分代码组成。1、CSS代码:ul#nav{width:100%;height:60px;background:#…

    2022年7月22日
    9
  • 浅析Java中float和double

    浅析Java中float和double需要注意的是 java 中小数默认为 double 类型的 如果想要使用 float 类型的 则需要在小数后面加 f 例如 floata 3 14f 不带符号的话 最小值 Float MIN VALUE 1 4E 45 2 的 149 次方 最小值 Double MIN VALUE 4 9E 324 2 的 1074 次方 最大值 Float MAX VALUE 3 E38 2 的 128 次方 1 最大

    2025年6月14日
    3

发表回复

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

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