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)
blank

相关推荐

  • screentogif全屏录制_录屏转gif手机版

    screentogif全屏录制_录屏转gif手机版作者:虚坏叔叔博客:https://xuhss.com早餐店不会开到晚上,想吃的人早就来了!?ScreenToGif录制软件的通用设置,优化使用体验在写博客的过程中习惯使用ScreenToGif来录制操作。在当下个人计算机性能内存搓搓有余的情况下,如何能够让这款软件非常好用呢?一、快捷键设置1.快速后台启动录屏窗口通过设置Ctrl+Alt+R能够快速启动软件二、关闭软件不退出有时,我需要让这个软件一直在后台运行,因为这块软件占的内存并不是很大:我们希望一直在后台运行即使关闭了

  • 数据结构学习笔记(二)–ElemType是什么?

    数据结构学习笔记(二)–ElemType是什么?ElemType(也有的书上称之为elemtp)是数据结构的书上为了说明问题而用的一个词。它是elementtype(“元素的类型”)的简化体。 因为数据结构是讨论抽象的数据存储和算法的,一种结构中元素的类型不一定是整型、字符型、浮点型或者用户自定义类型,为了不重复说明,使用过程中用“elemtype”代表所有可能的数据类型,简单明了的概括了整体。在算法中,除特别说明外,规定ElemType的默

  • 第10月第28天 touchesBegan hittest「建议收藏」

    第10月第28天 touchesBegan hittest「建议收藏」1.-(void)touchesBegan:(NSSet*)toucheswithEvent:(UIEvent*)event{[[selfnextResponder]touchesBegan:toucheswithEvent:event];[supertouchesBegan:toucheswithEvent:event];}-(voi…

  • vue子组件向父组件传值的方法

    vue子组件向父组件传值的方法子组件向父组件,使用$emit方法,demo:子组件的代码:<template><div><h1>thisischildcomponent</h1><button@click=”toParent”>向父组件传值</button></div>…

  • 分布式网站的通讯架构

    分布式网站的通讯架构

  • Initramfs_正在生成initramfs

    Initramfs_正在生成initramfs一、initramfs是什么  在2.6版本的linux内核中,都包含一个压缩过的cpio格式的打包文件。当内核启动时,会从这个打包文件中导出文件到内核的rootfs文件系统,然后内核检查rootfs中是否包含有init文件,如果有则执行它,作为PID为1的第一个进程。这个init进程负责启动系统后续的工作,包括定位、挂载“真正的”根文件系统设备(如果有的话)。如果内核没有在rootfs中

发表回复

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

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