Distribution money

Distribution money

Accepts: 713
Submissions: 1881
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
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.

Output

Output ID of the man who should be punished. If nobody should be punished,output -1.

Sample Input
3
1 1 2
4
2 1 4 3
Sample Output
1
-1
题意:随意排队领薪金,如果一个人领的超过其他人的总和那么这个人将受到惩罚输出这个人的工号,如果没人领的薪金超过其他人的总和输出-1
总共薪金是n,某个人可能领x,那么其他人的总和就是n-x,如果x>n-x即x>n/2,那么这个人领的薪金就超过其他人输出这个人的工号

 1 #include <iostream>
 2 #include <cstdlib>
 3 #include <cstdio>
 4 #include <algorithm>
 5 #include <vector>
 6 #include <queue>
 7 #include <cmath>
 8 #include <stack>
 9 #include <cstring>
10 
11 using namespace std;
12 
13 #define INF 0xfffffff
14 #define maxn 10005
15 
16 int main()
17 {
18     int n, x, i, k;
19     int cnt[maxn];
20 
21     while(scanf("%d", &n) != EOF)
22     {
23         memset(cnt, 0, sizeof(cnt));
24         k = -1;
25         for(i = 1; i <= n; i++)
26         {
27             scanf("%d", &x);
28             cnt[x]++;
29         }
30 
31         for(i = 0;  i<= 10000; i++)
32         {
33             if(cnt[i] > n/2)
34             {
35                  k = i;
36                  break;
37             }
38         }
39        printf("%d\n", k);
40     }
41     return 0;
42 }

 

转载于:https://www.cnblogs.com/Tinamei/p/4717098.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值