HDU-5123-who is the best?
题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=5123
水题一个,直接hash;
代码
#include<stdio.h>
#include<string.h>
int main(void)
{
int i,j,k,n,t;
int a[110];
int hash[110];
scanf("%d",&t);
while(t--)
{
memset(hash,0,sizeof(hash));
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",a+i);
hash[a[i]]++;
}
int Max=0,tragt;
for(i=1;i<=n;i++)
{
if(hash[i]>Max)
{
Max=hash[i];
tragt=i;
}
}
printf("%d\n",tragt);
}
return 0;
}
官方解析
1001 who is the best?
我们对于每个ai都进行计数,即b[ai]++,如此之后,我们可以一个循环语句i=1−>n来寻找最大的bi,注意此时应是bi>MAX,而不是bi≤MAX,这样才能保证出现的是编号最小的。另外需要注意的是每次做完后数组应当清0,否则会影响下次的答案,由于各种非确定性因素我在小数据就已经把没清0的程序卡死了。
HDU-5123-who is the best?的更多相关文章
- HDU 4978 A simple probability problem
A simple probability problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
- hdu 4329
problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟 a. p(r)= R'/i rel(r)=(1||0) R ...
随机推荐
- jaxb异常 Class has two properties of the same name username
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; im ...
- 关于数据结构的10个面试题(c语言实现)
关于数据结构的10个面试题(c语言实现) 2010-04-21 22:17 5702人阅读 评论(0) 收藏 举报 数据结构面试c语言bttree 1. 输入一个链表的头结点,从尾到头 ...
- Python3基础 定义有参数有返回值函数 对传入的参数加1
镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...
- HDU 5172 GTY's gay friends 线段树
GTY's gay friends Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- Task 编程中的异常处理
在 .Net 开发中, 使用 Task . Task<T> 进行异步编程是非常方便的, 但是在处理 Task 产生的异常时, 需要注意一个问题, 比如下面的代码: ? 1 2 3 4 5 ...
- 只有mdf 没有 日志 恢复数据库
1.先建一个与你要恢复的数据库名称一样的数据库.2.停止sql server,把你的数据库替换这个数据库.3.重启sql server,把数据库设置为紧急状态. sp_configure 'allo ...
- openssl使用+Demo
1. websiteSSL(secure Socket Layer)TLS(transport Layer Security) - SSL3.0基础之上提出的安全通信标准,目前版本是1.0openss ...
- HDU 3255 Farming
矩形面积并变形,一层一层的算体积 #include<cstdio> #include<cstring> #include<cmath> #include<ma ...
- JAV基础语法之---数据类型转换
数制转换": 1.string 转 byte[] String str = "Hello";byte[] srtbyte = str.getBytes(); 2.byte ...
- NBUT 1457 Sona
莫队算法+离散化 1.map会TLE,必须离散化做 2.long long会WA,__int64定义 %I64d输出输出能AC 3.注意输入的序列会爆int #include<cstdio> ...