HDU 1280 前m大的数【哈希入门】
题意:中文的题目= =将各种组合可能得到的和作为下标,然后因为不同组合得到的和可能是一样的,
所以再用一个数组num[]数组,就可以将相同的和都记录下来
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<algorithm>
using namespace std; typedef long long LL;
int hash[],a[],num[]; int main()
{
int n,m,i,j,k;
while(scanf("%d %d",&n,&m)!=EOF)
{
memset(hash,,sizeof(hash));
memset(num,,sizeof(num));
for(i=;i<=n;i++) cin>>a[i]; for(i=;i<=n;i++){
for(j=i+;j<=n;j++)
hash[a[i]+a[j]]++;//将各种相加可能出现的数作为下标
} for(i=,k=;k<m;i--){
while(hash[i]--) num[k++]=i;
} for(i=;i<m;i++){
if(i!=m-) printf("%d ",num[i]);
else printf("%d",num[i]);
}
printf("\n");
}
return ;
}
HDU 1280 前m大的数【哈希入门】的更多相关文章
- hdu 1280 前m大的数 哈希
前m大的数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- 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大的数(排序)
题意:排序 思路:排序 #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 ...
随机推荐
- mysql 的存储过程调试软件
免费下载链接:http://download.csdn.net/detail/meiyoudao/6371137 需要注册 调试还是 F10 类似的
- jquery each函数对应的continue 和 break方法
continue: return true; break: return false; $("#oGrid").each(function (i, v) { if (i == 0) ...
- 【POJ】【2151】Check the difficulty of problems
概率DP kuangbin总结中的第8题 一开始题目看错导致想转移方程想错了……想成f[i][j]表示前 i 个队伍中最多的做出来 j 道题的概率……sigh 看了下题解……其实是对于每个队伍 i 单 ...
- BZOJ1692: [Usaco2007 Dec]队列变换
1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 594 Solved: 246[Submit][Sta ...
- nenu contest
http://vjudge.net/vjudge/contest/view.action?cid=54393#overview A n^2能过 对第二个n我二分了一下,快了一点点,nlogn #inc ...
- Unity3D脚本中文系列教程(八)
◆ static var matrix : Matrix4x4 描述:设置用于渲染所有gizmos的矩阵. 类方法 ◆ Static function DrawCube(center:Vector3, ...
- Unity3d Android程序嵌入Admob广告条
原地址:http://dong2008hong.blog.163.com/blog/static/4696882720140441353482/ Seems like using a simple A ...
- C++中的const关键字
http://blog.csdn.net/eric_jo/article/details/4138548 C++中的const关键字的用法非常灵活,而使用const将大大改善程序的健壮性,本人根据各方 ...
- longene QQ 安装目录
longene QQ 在Ubuntu 12.04上的安装目录如下: wy@wy-Inspiron-7420:~/.longene/qq/drive_c/Program Files/Tencent/QQ ...
- iOS开发--数组
1.sortedArrayUsingSelector (按Key值大小对NSDictionary排序) NSMutableArray *array = [NSMutableArray arrayWit ...