zoukankan      html  css  js  c++  java
  • POJ 2370 Democracy in danger(简单贪心)

    Democracy in danger
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 3388   Accepted: 2508

    Description

    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.
    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

    The input of this problem contains two lines. In the first line an only natural number K <= 101 — a quantity of groups — is written. In the second line there are written K natural numbers, separated with a space. Those numbers define a number of voters in each group. In order to simplify the notion of "the majority of votes" we'll say that the number of groups also as the number of voters in each group is odd. You may also consider, that the population of the island does not exceeds 10001 persons.

    Output

    You should write an only natural number — a minimal quantity of supporters of the party, that can put into effect any decision.

    Sample Input

    3
    5 7 5
    

    Sample Output

    6

    Source

    题目链接:http://poj.org/problem?id=2370
    题解:以前挂的一些贪心的题没有做,有位大佬叫我写下题解,有些看不懂题意,我恭敬不如从命了,写点吧,算是复习下贪心吧!
    题目大意是关于投票,已知k个组,这k个组中只要有一半以上通过了,就算通过了所以取k/2+1;要想去最少的通过人数,就想办法使得这k/2+1这些组的人数都是最少的,这时可以进行排序,然后取前k/2+1个组;每个组中只要有一半以上的人通过了,就算通过了,所以只要这些k/2+1组的每组超过一半的人通过了,就通过了;及a/2+1,a为每组的人数!
    下面给出AC代码:
     1 #include <iostream>
     2 #include <cstring>
     3 #include <algorithm>
     4 #include <cstdio>
     5 using namespace std;
     6 int main()
     7 {
     8     int a[110];
     9     int n;
    10     while(scanf("%d",&n)!=EOF)
    11     {
    12         for(int i=0;i<n;i++)
    13             scanf("%d",&a[i]);
    14         sort(a,a+n);
    15         int sum=0;
    16         for(int i=0;i<n/2+1;i++)
    17             sum+=a[i]/2+1;
    18             printf("%d
    ",sum);
    19     }
    20     return 0;
    21 }
  • 相关阅读:
    常用的IDEA快捷键
    异步任务 & 定时任务 & 邮件任务
    Swagger
    路由钩子&异步请求axios
    vue-参数绑定及重定向
    Spring事务的传播机制
    使用mybatis的BaseTypeHandler来给敏感字段进行AES加密
    SpringBoot2.0.3.RELEASE+sharding-jdbc4.1.0+mybatis-plus3.4.1+druid1.1.22 快速搭建分库分表
    使用SpringCloudStream整合RabbitMQ
    获取汉字首字母
  • 原文地址:https://www.cnblogs.com/ECJTUACM-873284962/p/6590681.html
Copyright © 2011-2022 走看看