URAL 1025. Democracy in Danger (贪心)

1025. Democracy in Danger

Time limit: 1.0 second

Memory limit: 64 MB

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 output
3
5 7 5
6

Problem Author: Leonid Volkov

Problem Source: Ural State University Internal Contest October‘2000 Junior Session

题意:奇数K场投票,每场奇数Ki个人,最少用多少人投赞成票才能赢得竞选。

解析:赢得(K/2) + 1场即可,每场需(Ki/2)+1人投赞成票,贪心选择人数最少的场数。

AC代码:

#include <bits/stdc++.h>
using namespace std;

int a[102];

int main(){
    int n;
    while(scanf("%d", &n)!=EOF){
        for(int i=0; i<n; i++) scanf("%d", &a[i]);
        sort(a, a+n);
        int sum = 0;
        for(int i=0; i<(n/2) + 1; i++){
            sum += (a[i]/2) + 1;
        }
        printf("%d\n", sum);
    }
    return 0;
}
时间: 2024-10-17 00:35:21

URAL 1025. Democracy in Danger (贪心)的相关文章

URAL 1025 Democracy in Danger

排个序 1 import java.util.Arrays; 2 import java.util.Scanner; 3 4 public class P1025 5 { 6 public static void main(String args[]) 7 { 8 try (Scanner cin = new Scanner(System.in)) 9 { 10 while (cin.hasNext()) 11 { 12 int n = cin.nextInt(); 13 int a[] = n

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 citize

POJ2370 Democracy in danger

题目超级水,但题目意思不好理解(英语太差...),排个序,然后答案就出来了. Democracy in danger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3136   Accepted: 2311 Description In one of the countries of Caribbean basin all decisions were accepted by the simple majority of

URAL 1203 Scientific Conference(贪心 || DP)

Scientific Conference 之前一直在刷计算几何,邀请赛连计算几何的毛都买见着,暑假这一段时间就做多校,补多校的题目,刷一下一直薄弱的DP.多校如果有计算几何一定要干掉-.- 题意:给你N个报告会的开始时间跟结束时间,问你做多可以听几场报告会.要求报告会之间至少间隔为1. 思路:其实是个活动安排问题,可以用贪心也可以用DP,贪心写起来会比较简单一些,因为练习DP,所以又用DP写了一遍. 贪心的话就是一个很简单的活动选择问题,从结束时间入手,找每次的最优选择. 1 struct n

SGU 410 Galaxy in danger --贪心,想法题

题意:有n个星球,每个星球有Ai个人,每次有两种选择,第一是从每个星球上去掉1个人,第二个选择是选择一个星球放置一个科学家,将该星球的人数加倍,问最少多少次能够将所有星球上的人数同时变为0,并且如果步数<=1000,还要输出操作顺序. 解法:找出人数最多的那个星球,设最大人数为maxi,那么跑一个循环,每次该星球如果人数<maxi,那么能加倍就加倍到离maxi最近的位置,然后计算他们的差,比如2 1035,加倍后为1024 1035,差为11,那么到时候1024减到11的时候,1035变成了2

URAL 2026 Dean and Schedule 贪心、双端队列(deque)、队列(queue)

C - Dean and Schedule Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice URAL 2026 Description A new academic year approaches, and the dean must make a schedule of classes for first-year students. Ther

Ural 1303 Minimal Coverage(贪心)

题目地址:Ural 1303 先按每个线段的左端点排序,然后设置一个起点s,每次都从起点小于等于s的线段中找到一个右端点最大的.并将该右端点作为新的起点s,然后继续找.从左到右扫描一遍即可. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #inc

poj 2370 Democracy in danger

题目链接:http://poj.org/problem?id=2370 题意:大意好像是类似选举,给出K,表示一共K组,然后给出K组人每组的人数,都是奇数.每组人有超过一半的人同意就认为那一组人同意,有超过半数的组同意就决定通过,看最少要多少人同意能决定通过. 分析:贪心.(水)将每组人数按照从小到大排序,选择前面(k)/2+1组人每组a[i]/2+1的人同意就好. 代码: #include<cstdio> #include<cmath> #include<cstring&g

11 URAL1025 Democracy in Danger

选择人数较少的m/2只队,每只队中半数人投票. #include<cstdio> #include<algorithm> using namespace std; int main() { int i,n,ans,s[110]; while(~scanf("%d",&n)) { for(i=0;i<n;i++) scanf("%d",&s[i]); sort(s,s+n); ans=0; for(i=0;i<=n/