HDU 5364 Distribution money——BestCoder Round #50(div.2)
2015-08-08 23:00
197 查看
Distribution money
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
Source
BestCoder Round #50 (div.2)
/************************************************************************/
附上该题对应的中文题
Distribution money
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
问题描述
地主小花难得当一回好人,这次她准备给长工们发津贴。有些长工会偷偷地在领完津贴后又排回队伍里去领津贴。不过小花对此表示无所谓,因为她发的是固定数额的津贴。但是如果有人领到的津贴超过其他所有人的总和的话,小花为了显示自己的公正,会去惩罚他。现已知每个来领津贴的人会登记下自己的工号。
输入描述
输入有多组数据,每组第一行为一个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.
/****************************************************/
出题人的解题思路:
这题没什么好说的,排个序直接模拟一下就好了
好吧,这题的确是水题,不过刚开始没有重视“如果有人领到的津贴超过其他所有人的总和”这句话,然后傻傻地找了出现次数最多的工号,然后果断WA了。这题其实只要记录一下每个工号出现的次数s[i],然后判断一下s[i]>n-s[i]是否成立即可。
有一点想要提一下,
3
0 0 2
这组数据,结果应该是0,但是一些人输出-1居然也过了,而且最后重判也没有判错,也是醉了,好啦,水题就这样过了。
我的代码不是最优的,仅作为参考,有疑问可以提出来,谢谢
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<queue> #include<math.h> #include<vector> #include<map> #include<set> #include<cmath> #include<string> #include<algorithm> #include<iostream> #define exp 1e-10 #define ll __int64 using namespace std; const int N = 10005; const int inf = 1000000000; const int mod = 1000000007; int s ; int main() { int n,i,k,a,j,Min,Max; while(~scanf("%d",&n)) { k=0;Min=inf;Max=-inf; memset(s,0,sizeof(s)); for(i=0;i<n;i++) { scanf("%d",&a); s[a]++; Min=min(a,Min); } for(i=Min;i<10000;i++) if(s[i]&&s[i]>n-s[i]) break; if(i!=10000) printf("%d\n",i); else puts("-1"); } return 0; }菜鸟成长记
相关文章推荐
- Android 中odex转成dex
- mysql 分库备份
- android的Http协议学习与应用——连接一个网页
- 第一个QT文件为毛编译不出来
- 左移 & 右移
- 第80讲:List的泛型分析以及::类和Nil对象学习笔记
- ubuntu 安装ATI驱动
- 【Java多线程】之一:Thread Simple Example
- codeforecs Gym 100286B Blind Walk
- linux shell 逻辑运算符、逻辑表达式详解
- http头中的host字段详解
- 原生JavaScript封装的ajax提交表单form
- 【HDU】5367 digger【动态线段树】
- Scrapy 安装问题集锦
- c语言的基础复习
- scala实现原型模式
- c/c++语言中sort函数的使用方法
- 《Redis设计与实现》读书笔记
- [学习笔记]JavaScript基础--任意值运动框架
- 64.Minimum Path Sum