• 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
    ", k);
    40     }
    41     return 0;
    42 }
    让未来到来 让过去过去
  • 相关阅读:
    bzoj 3527: [Zjoi2014]力
    bzoj 1797: [Ahoi2009]Mincut 最小割
    bzoj 1028: [JSOI2007]麻将
    bzoj 1019: [SHOI2008]汉诺塔
    bzoj 1023: [SHOI2008]cactus仙人掌图
    bzoj 3289: Mato的文件管理
    bzoj 4034: [HAOI2015]T2
    bzoj 1218: [HNOI2003]激光炸弹
    bzoj 2431: [HAOI2009]逆序对数列
    The full stack trace of the root cause is available in the Apache Tomcat/8.0.8 logs.
  • 原文地址:https://www.cnblogs.com/Tinamei/p/4717098.html
Copyright © 2020-2023  润新知