hdu 1280 前m大的数 哈希
前m大的数
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10574 Accepted Submission(s): 3686
给定一个包括N(N<=3000)个正整数的序列,每一个数不超过5000。对它们两两相加得到的N*(N-1)/2个和。求出当中前M大的数(M<=1000)并按从大到小的顺序排列。
第一行两个数N和M,
第二行N个数,表示该序列。
4 4
1 2 3 4
4 5
5 3 6 4
7 6 5 5
11 10 9 9 8
#include<stdio.h>
#include<cstring>
int main()
{
int hash[10010];
int a[3010];
int n,m;
int i,j;
while(scanf("%d %d",&n,&m)!=EOF)
{
memset(hash,0,sizeof(hash));
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
int xx=0;
for(i=0;i<n;i++)
{
for(j=0;j<i;j++)
{
hash[a[i]+a[j]]++;
if(a[i]+a[j]>xx)
{
xx=a[i]+a[j];
}
}
}
for(i=xx;i>=0;i--)
{
while(hash[i]&&m>1)
{
printf("%d ",i);
hash[i]--;
m--;
}
if(m==1&&hash[i])
{
printf("%d\n",i);
break;
}
}
}
return 0;
}
hdu 1280 前m大的数 哈希的更多相关文章
- HDU 1280 前m大的数
http://acm.hdu.edu.cn/showproblem.php?pid=1280 前m大的数 Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- HDU 1280 前m大的数【排序 / hash】
前m大的数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- HDU 1280 前m大的数(排序,字符串)
前m大的数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- <hdu - 1280> 前M大的数 (注意其中的细节)
这是杭电hdu上的链接http://acm.hdu.edu.cn/showproblem.php?pid=1280 Problem Description: 还记得Gardon给小希布置的那个作业么 ...
- HDU 1280 前m大的数 基数排序
http://acm.hdu.edu.cn/showproblem.php?pid=1280 题目大意: 给你N(N<=3000)个数(这些数不超过5000),要求输出他们两两相加后和最大的M( ...
- HDU 1280 前m大的数【哈希入门】
题意:中文的题目= =将各种组合可能得到的和作为下标,然后因为不同组合得到的和可能是一样的, 所以再用一个数组num[]数组,就可以将相同的和都记录下来 #include<iostream> ...
- hdu 1280 前m大的数(排序)
题意:排序 思路:排序 #include<iostream> #include<stdio.h> #include<algorithm> using namespa ...
- 杭电 1280 前m大的数
http://acm.hdu.edu.cn/showproblem.php?pid=1280 前m大的数 Time Limit: 2000/1000 MS (Java/Others) Memor ...
- hdu---(1280)前m大的数(计数排序)
前m大的数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
随机推荐
- DFA 算法实现关键词匹配
起因: 从网页中爬去的页面.须要推断是否跟预设的关键词匹配(是否包括预设的关键词),并返回全部匹配到的关键词 . 眼下pypi 上两个实现 ahocorasick https://pypi.pytho ...
- [Javascript] Prototype 2 Object.create()
function Fencepost (x, y, postNum){ this.x = x; this.y = y; this.postNum = postNum; this.connections ...
- Jmeter-Maven-Plugin高级应用:Configuring the jvm that the jmeter process runs in
Configuring the jvm that the jmeter process runs in The JMeter Maven plugin will run the JMeter proc ...
- 修改字段结构之GP工具
即然有这个需求,就有人这样做.有人写了GP工具直接来重命名字段名和字段别名.工具及源码下载链接为:http://www.t00y.com/file/90123888 加载到ToolBox中后,可直接运 ...
- ZOJ 2320 Cracking' RSA
其次布尔线性方程组,高斯消元.这道题目的关键部分是看的神牛watashi的思路.另附上watashi的思路 我把他的java模板翻译成了C++的了...存起来以后当模板用...a[i][j]表示第i个 ...
- 栈的应用实例——平衡符号
检查().[].{}是否配对. /* stack_balance_symbol */ #include "stack.h" #include <stdio.h> #in ...
- 深入浅出 - Android系统移植与平台开发(十三)- Android的对象管理
第六章.Android的对象管理 在Java中,不再使用的对象会通过gc机制来自己主动回收.而Android系统执行时库层代码是由C++编写的,在C++中创建的对象通常使用指针来操作,一旦使用不当.轻 ...
- linux安装JDK环境,JDK6.0即java 1.6.0
下载 (1)更改权限:# chmod 755 jdk-1.6.0_23-linux-i586.rpm.bin 执行安装:# ./ jdk-1.6.0_23-linux-i586.rpm.bin 此步完 ...
- ecipse theme
市场里搜“jeeeyul's Eclipse Themes”
- eclipse 修改maven项目的jdk版本
eclipse 修改maven项目的jdk版本 CreationTime--2018年6月8日10点29分 Author:Marydon 1.情景展示 jdk版本太低,如何修改 2.错误方式 第一 ...