Ural 1025-Democrary in Danger

2024-02-07 16:50
文章标签 ural 1025 danger democrary

本文主要是介绍Ural 1025-Democrary in Danger,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

问题描述】

    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 102using 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

这篇关于Ural 1025-Democrary in Danger的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/688346

相关文章

ural 1297. Palindrome dp

1297. Palindrome Time limit: 1.0 second Memory limit: 64 MB The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unli

ural 1149. Sinus Dances dfs

1149. Sinus Dances Time limit: 1.0 second Memory limit: 64 MB Let  An = sin(1–sin(2+sin(3–sin(4+…sin( n))…) Let  Sn = (…( A 1+ n) A 2+ n–1) A 3+…+2) An+1 For given  N print  SN Input One

ural 1820. Ural Steaks 贪心

1820. Ural Steaks Time limit: 0.5 second Memory limit: 64 MB After the personal contest, happy but hungry programmers dropped into the restaurant “Ural Steaks” and ordered  n specialty steaks

ural 1017. Staircases DP

1017. Staircases Time limit: 1.0 second Memory limit: 64 MB One curious child has a set of  N little bricks (5 ≤  N ≤ 500). From these bricks he builds different staircases. Staircase consist

ural 1026. Questions and Answers 查询

1026. Questions and Answers Time limit: 2.0 second Memory limit: 64 MB Background The database of the Pentagon contains a top-secret information. We don’t know what the information is — you

ural 1014. Product of Digits贪心

1014. Product of Digits Time limit: 1.0 second Memory limit: 64 MB Your task is to find the minimal positive integer number  Q so that the product of digits of  Q is exactly equal to  N. Inpu

后缀数组 - 求最长回文子串 + 模板题 --- ural 1297

1297. Palindrome Time Limit: 1.0 second Memory Limit: 16 MB The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unlim

【URAL】1057 Amount of Degrees 数位DP

传送门:【URAL】1057 Amount of Degrees 题目分析:将数转化成能达到的最大的01串,串上从右往左第i位为1表示该数包括B^i。 代码如下: #include <cstdio>#include <cstring>#include <algorithm>using namespace std ;typedef long long LL ;#de

ural Minimal Coverage (区间覆盖)

http://acm.timus.ru/problem.aspx?space=1&num=1303 给出一些区间,选择尽量少的区间能覆盖到[0,m]。 小白p154,典型的区间覆盖问题。一直在想怎么dp。。 首先预处理,先按左端点从小到大排序,若左端点相同右端点从大到小排序,若区间x完全包含y,按照贪心的思想,y是没有意义的,有大区间可以选何必选择小区间。处理完事之后各个区间满足a1

ural Binary Lexicographic Sequence (dp + dfs)

http://acm.timus.ru/problem.aspx?space=1&num=1081 有一个二进制序列,定义为不能有两个连续的1出现,才是合法的。给出序列的长度n,求合法的二进制序列中按字典序排序后第k个序列是什么。 设dp[i][0]和dp[i][1]分别表示第i位上是0和1的个数。 那么dp[i][0] = dp[i-1][0] + dp[i-1][1];dp[