HDU 5364-Distribution money(水题)

题目地址:HDU 5364

中文题意:

问题描述

地主小花难得当一回好人,这次她准备给长工们发津贴。有些长工会偷偷地在领完津贴后又排回队伍里去领津贴。不过小花对此表示无所谓,因为她发的是固定数额的津贴。但是如果有人领到的津贴超过其他所有人的总和的话,小花为了显示自己的公正,会去惩罚他。现已知每个来领津贴的人会登记下自己的工号。

输入描述

输入有多组数据,每组第一行为一个n(1 < = n < = 1000),表示有多少津贴被领,第二行n个数字a1,a2…an,表示n个来领津贴的人的工号(0 < = a[i] < 10000)。

输出描述

输出一个数字,表示被惩罚的人的工号。

若没有人需要被惩罚,则输出-1。

输入样例

3

1 1 2

4

2 1 4 3

输出样例

1

-1

Hint

第一个样例中,1号工人拿走的钱超过其他所有人总和,所以输出1。

第二个样例中,没有拿到的钱超过其他所有人的总和,所以输出-1.

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const double pi= acos(-1.0);
const double esp=1e-6;
const int maxn=10010;
int a[maxn];
int vis[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n)){
        memset(vis,0,sizeof(vis));
        int flag=0;
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
            vis[a[i]]++;
            if(vis[a[i]]>n/2){
                flag=a[i];
            }
        }
        if(!flag)
            puts("-1");
        else
            printf("%d\n",flag);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-08-30 04:39:31

HDU 5364-Distribution money(水题)的相关文章

简单的dp hdu 数塔(水题)

数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 21314    Accepted Submission(s): 12808 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少

hdu 2053 Switch Game 水题一枚,鉴定完毕

Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10200    Accepted Submission(s): 6175 Problem Description There are many lamps in a line. All of them are off at first. A series of op

HDU 2090 算菜价 --- 水题

/* HDU 2090 算菜价 --- 水题 */ #include <cstdio> int main() { char s[105]; double a, b, sum = 0; while (scanf("%s", s)==1){ scanf("%lf%lf", &a, &b); a *= b; sum += a; } printf("%.1f\n", sum); return 0; }

HDU 2091 空心三角形 --- 水题

/* HDU 2091 空心三角形 --- 水题 */ #include <cstdio> int main() { int kase = 0; char ch; int h, t; //h表示高 while (scanf("%c", &ch) == 1 && ch != '@'){ scanf("%d", &h); if (kase++){ printf("\n"); } getchar(); if

hdu 2212 DFS(水题)

DFS Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4923    Accepted Submission(s): 3029 Problem Description A DFS(digital factorial sum) number is found by summing the factorial of every digit

hdu 5007(字符串水题)

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5007 Post Robot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 327    Accepted Submission(s): 253 Problem Description DT is a big fan of digital

HDOJ/HDU 2560 Buildings(嗯~水题)

Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, the green grids represent the buidings. Given the size of the HZNU Campus, and the color of each grid, you should count how many green grids in the N

HDU 3316 爆搜水题

爆搜水题 模拟扫雷,规则和扫雷一样 给出原图,求在X,Y位置点一下以后的图形,没有弹出的点输出-1,弹出的点输出这个点的数字 从起始点DFS一下即可 #include "stdio.h" #include "string.h" int dir[8][2]={ {-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1} }; int n; int hash[110][110]; char str[110][110]; i

hdu 5835 Danganronpa 贪心+水题

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5835 [题意]有n种礼物,每个有ai个,现在开始给每个人发礼物,每人一个普通礼物和神秘礼物,相邻两人的普通礼物必须不同,每个礼物都可以作为神秘礼物/普通礼物,问最多可以发给多少人. [解题思路] 答案肯定是小于等于sum/2,因为每个小朋友得有2礼物.然而数据太水,sum/2也过了. 我们先考虑平凡的礼物,因为平凡的礼物相邻桌子上不能相同,故先把数量最多的礼物相邻的交替用作平凡的礼物. 如果n=3,

hdu 5232 Shaking hands 水题

Shaking hands Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5232 Description Today is Gorwin’s birthday, so she holds a party and invites her friends to participate. She will invite n friends, for convenience