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 ...
随机推荐
- ubuntu下搭建nfs,tftp,安装qt等一些基本的启动bootloader前的服务
之前做三星的6410是在红帽下做的,现在公司给了个TI的AM3359的开发板,开发环境是ubuntu10-04.这周经过半天的研究对比,终于算是搭好tftp下载的一些服务了. [防火墙] sudo u ...
- sqlserver 2008 卸载时提示 “重新启动计算机”失败
问题:sqlserver 2008 卸载时提示 “重新启动计算机”失败 解决办法: 1.打开注册表:开始->运行: regedit 2.找到HKEY_LOCAL_MACHINE\SYSTEM\C ...
- 2208: [Jsoi2010]连通数 - BZOJ
Description Input 输入数据第一行是图顶点的数量,一个正整数N. 接下来N行,每行N个字符.第i行第j列的1表示顶点i到j有边,0则表示无边. Output 输出一行一个整数,表示该图 ...
- JS实现Web网页打印功能(IE)
问题描述: JS实现Web网页打印功能 问题解决: 这里主要使用WebBrowser控件的ExeWB在IE中打印功能的实现 WebBrowser介绍: WebBrows ...
- hdu 4888
网络流建模,建模不难,难在找环: #include<cstdio> #include<algorithm> #include<vector> #include< ...
- recursion lead to out of memory
There are two storage areas involved: the stack and the heap. The stack is where the current state o ...
- SPOJ LGLOVE 7488 LCM GCD Love (区间更新,预处理出LCM(1,2,...,n))
题目连接:http://www.spoj.com/problems/LGLOVE/ 题意:给出n个初始序列a[1],a[2],...,a[n],b[i]表示LCM(1,2,3,...,a[i]),即1 ...
- HttpWebRequest和HttpWebResponse
原文:http://blog.csdn.net/haitaofeiyang/article/details/18362225 申公前几日和一个客户做系统对接,以前和客户对接一般采用webservice ...
- ASP.NET连接数据库并获取数据
关键词:连接对象的用法SqlConnection,SqlCommand,SqlDataAdapter *数据访问方式的写法 工具/原料 VS SQL SERVER 2012 R2 方法/步骤1: 1. ...
- apache配置优化
最近参加了很多面试,多多少少有点小感悟,可以说观念转变了不少,特别是对于作为一个开发人员的定位,原来只是认为开发人员就只需要写好代码就行了,所以只需要有数据结构,算法,设计模式,重构方面的知识就行了. ...