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 ... 
随机推荐
- 谈谈javascript的函数作用域
			在一些类似c语言的编程语言中,花括号内的每一段代码都具有各自的作用域,而且变量在声明他们的代码段之外是不可见的,我们称为块级作用域(block scope),而javascript中没有块级作用域.取 ... 
- 浅议 android下的context
			android学习中,最开始学习的一个类是activities,你是否知道他与context之间 的关系,我们经常用startactivities来唤起一个activities他的定义有在哪里了,他是 ... 
- Java Object Clone
			Java Object Clone User user = new User(); user.setName("tom"); User user1 = new User(); us ... 
- jQuery cssHook的经典例子
			/*--------------------------- example ------------------------------*/ $.cssHooks.foo = { get: fun ... 
- Android Studio 3.0 下载 使用新功能介绍
			谷歌2017发布会更新了挺多内容的,而且也发布了AndroidStudio3.0预览版,一些功能先睹为快.(英语一般,有些翻译不太好) 下载地址 https://developer.android.g ... 
- Android直播实现 Android端推流、播放
			最近想实现一个Android直播,但是对于这方面的资料都比较零碎,一开始是打算用ffmpeg来实现编码推流,在搜集资料期间,找到了几个强大的开源库,直接避免了jni的代码,集成后只用少量的java代码 ... 
- [NPM] Execute npx commands with $npm_ Environment Variables
			We will incorporate npm specific environment variables when executing various npx commands. In our e ... 
- [CSS] Collapsing Margins
			Refactor the spacing between <header>, <article>, and <aside> so that elements wil ... 
- [Node.js]32. Level 7: Working with Lists -- Redis
			As we saw in the video, redis can do more than just simple key-value pairs. We are going to be using ... 
- oracle错误处理之ORA-00054:资源正忙,要求指定NOWAIT
			查询所有会话 select t2.username, t2.sid, t2.serial#, t2.logon_time from v$locked_object t1, v$session t2 w ... 
