HDU 5364 Distribution money

Problem Description

AFA want to distribution her money to somebody.She divide her money into n same parts.One who want to get the money can get more than one part.But if one man‘s money is more than the sum of all others‘.He shoule be punished.Each one who get a part of money would write down his ID on that part.

Input

There are multiply cases.
For each case,there is a
single integer n(1<=n<=1000) in first line.
In second line,there are n
integer a1,a2...an(0<=ai<10000)ai is the the ith man‘s ID.

sample input

3

1 1 2

4

2 1 4 3

sample output

1

-1

题意

地主给排着队的长工发工资,每份工资是一样的,领了工资的人会留下工号,但是有的人对领完之后回到队尾再领,如果有人领的工资比其他所有人只和还多,试求是否有这样的人以及他的编号。

题解

题意也就是寻找序列中出现次数超过一半的元素,可以先排序,然后计算中间位置元素的数量(二分),超过一半就是答案,小于一半则无解

#include<stdio.h>
#include<iostream>
#include<algorithm>

using namespace std;

int a[1002];

int main(void)
{
    //freopen ("in.txt","r",stdin);
    int n,k;

    while (scanf("%d",&n)!=EOF)
    {
        for (int i=1;i<=n;++i) scanf("%d",&a[i]);
        sort(a+1,a+1+n);
        k=a[(1+n)/2];
        if (upper_bound(a+1,a+1+n,k)-lower_bound(a+1,a+1+n,k)>n/2) printf("%d\n",k);
        else printf("-1\n");

    }

}
时间: 2024-11-05 15:42:39

HDU 5364 Distribution money的相关文章

hdu 5364 (bc#50 1001) Distribution money

Distribution money Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 276    Accepted Submission(s): 163 Problem Description AFA want to distribution her money to somebody.She divide her money into

HDU 5364 5366

Distribution money Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 511    Accepted Submission(s): 291 Problem Description AFA want to distribution her money to somebody.She divide her money int

hdu 5364

#include <iostream>#include <stdio.h>#include<math.h>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std; int main(){ int n,s[1005]; int u,flag,min; while(cin>>n) { min=u=0; memset(s,0,10

HDU 5364-Distribution money(水题)

题目地址:HDU 5364 中文题意: 问题描述 地主小花难得当一回好人,这次她准备给长工们发津贴.有些长工会偷偷地在领完津贴后又排回队伍里去领津贴.不过小花对此表示无所谓,因为她发的是固定数额的津贴.但是如果有人领到的津贴超过其他所有人的总和的话,小花为了显示自己的公正,会去惩罚他.现已知每个来领津贴的人会登记下自己的工号. 输入描述 输入有多组数据,每组第一行为一个n(1 < = n < = 1000),表示有多少津贴被领,第二行n个数字a1,a2-an,表示n个来领津贴的人的工号(0 &

BestCoder Round #50 (div.1) 1001 Distribution money (HDU OJ 5364)

题目:Click here 题意:bestcoder上面有中文题目 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <cmath> 6 #include <string> 7 #include <climits> 8 #include <vector> 9 #incl

hdu 5291 Candy Distribution(dp)

题目链接:hdu 5291 Candy Distribution 每次先计算出dp[0],然后根据dp[0]的数值可以用o(1)的复杂度算出dp[1],以此类推.总体复杂度为o(200 * 80000),可以接受. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 80000; const int maxm = 205; cons

hdu 5155(DP)

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5155 Harry And Magic Box Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 273    Accepted Submission(s): 137 Problem Description One day, Harry got

HDU 1541 Stars (树状数组)

Problem Description Astronomers often examine star maps where stars are represented by points on a plane and each star has Cartesian coordinates. Let the level of a star be an amount of the stars that are not higher and not to the right of the given

HDU 5880 Family View (AC自动机)

Family View Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Description Steam is a digital distribution platform developed by Valve Corporation offering digital rights management (DRM), multiplayer gaming and socia