HDU1425整数HASH
来源:互联网 发布:人体工学椅 知乎 推荐 编辑:程序博客网 时间:2024/05/16 19:40
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1425
由于题目数据很水所以用快排居然也过了
但是必须知道的是 一般情况下当数据范围超过1e5的时候快排就会超时的
快排的时间复杂度为O(nlog(n)),而此题 为O(n);
快排
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;int a[1000000];bool cmp(int a,int b){ return a>b;}int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { for(int i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n,cmp); for(int i=0;i<m-1;i++) printf("%d ",a[i]); printf("%d\n",a[m-1]); } return 0;}
hash
#include <iostream>#include <cstring>#include <cstdio>using namespace std;const int maxn = 1000005;int a[maxn];int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { int t; memset(a,0,sizeof(a)); for(int i=0;i<n;i++) { scanf("%d",&t); a[500000+t]=1; } for(int i=1000001;m>0;i--) { if(a[i]) { printf("%d",i-500000); if(m>1) printf(" "); else puts(""); m--; } } } return 0;}
0 0
- HDU1425整数HASH
- hdu1425 sort (hash)
- hdu1425 排序+hash
- hdu1425
- HDU1425
- HDU1425
- hdu1425最简单hash(加速输入外挂。。)
- 整数hash
- 整数的Hash函数
- 整数Hash的应用
- HDU1280整数hash
- hdu 1496 整数hash
- HDU 1496 整数Hash
- hdu1425 sort
- HDU1425:sort
- HDU1425-sort
- HDU1425----sort
- hdu1425.sort
- Zlib文件压缩和解压
- Arduino的ADXL345库文件(附下载链接)
- Android的系统架构
- 【Android学习笔记】Intent的基本作用
- 从 MFC 3.0 升级到 8.0 后不受支持的 eVC 类的列表
- HDU1425整数HASH
- python学习笔记:泊松分布和负指数分布随机数的python实现
- POJ 1703 && poj 1182【典型并查集】
- 《XML实用大全》一
- 支持向量机(SVM)非线性数据分割
- FileZilla 连接成功,但读取列表失败解决方案。
- 用于运行 ASP.NET 的进程帐户必须具有对 IIS 元数据库(如 IIS://servername/W3SVC)的读访问权
- 打包时字符串多国语言问题(Checks for incomplete translations where not all strings are translated)
- 的费用和韩国