HDU-1280(哈希表求法)
来源:互联网 发布:北京网络咨询医生招聘 编辑:程序博客网 时间:2024/06/06 19:29
题目名称:前m大的数 题目链接:https://vjudge.net/problem/HDU-1280
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#define getHassVal(i, j) arr[i] + arr[j]using namespace std;const int MAXN = 1500000;int arr[5000];int hashMap[MAXN];int main(){ int n, m; while(scanf("%d%d", &n, &m) != EOF) { memset(hashMap, 0, sizeof(hashMap)); for(int i = 0; i < n; ++i) cin >> arr[i]; for(int i = 0; i < n; ++i) for(int j = i + 1; j < n; ++j) hashMap[getHassVal(i, j)]++; int flag = 0; for(int i = MAXN - 1; i > 0&&m>0; ) { if(hashMap[i] == 0){i--; continue;} if(flag) cout << ' ' << i; else cout << i; flag = 1; hashMap[i]--; m--; } cout << endl; }}
阅读全文
0 0
- HDU-1280(哈希表求法)
- hdu 1042_N!的高精度求法
- hdu 1722Cake(公约数的应用和求法)
- hdu 2028 && 1019 (最小公倍数的几种求法)
- hdu 4291矩阵乘法,幂的应用,循环节的求法
- hdu 2544 【总结】 Dijkstra,Bellman-Ford ,SPFA 最短路求法及对应优化
- hdu 1025(最长非递减子序列的n*log(n)求法)
- HDU 3037 组合数求法(模板)(Fermat's Law + Lucass's Law)
- hdu 3117 Fibonacci Numbers 斐波那契数列前四位求法
- HDU 2196 浅谈树上多源最长路动态规划求法
- 阶乘求法
- 最大公约数求法
- 最大公约数求法
- 素数求法
- 素数求法
- 最大公约数求法
- Sa求法
- 质数求法
- ubuntu ssh 显示界面
- Content Provider 详解
- Warning: require(): open_basedir restriction in effect. File(/home/framework/laravel/
- IDEA2017注册码
- Servlet--获取信息
- HDU-1280(哈希表求法)
- 网络基础
- Mysql启动时发生系统错误 5,拒绝访问
- MongoDB入门学习
- 从串口驱动到Linux驱动模型
- tomcat的运作和性能调优杂谈
- acm G
- 八种排序算法
- 并发基本概念