hdu1425 sort(哈希表)
来源:互联网 发布:索引超出数据界限 编辑:程序博客网 时间:2024/05/16 01:19
很久以前用素数打表时就见识到了这种算法,今天才知道是HASH。
这应该是最简单的哈希吧,虽然优化了,但我的为毛还是700ms+
普通快排水过:
#include <stdio.h>#include <algorithm>#include <string.h>using namespace std;const int N = 1000005;int main(){ // freopen("in.txt", "r", stdin); int n, m, a[N]; while(~scanf("%d%d", &n, &m)) { for(int i = 0; i < n; i ++) scanf("%d", &a[i]); sort(a, a + n); int num = 0, i; for(i = n - 1; i >= 0; i --) { if(num == m - 1) break; num ++; printf("%d ", a[i]); } printf("%d", a[i]); printf("\n"); } return 0;}
哈希方法:
#include <stdio.h>#include <algorithm>#include <string.h>using namespace std;const int N = 1000005;int main(){ // freopen("in.txt", "r", stdin); int n, m, a[N]; while(~scanf("%d%d", &n, &m)) { int num0; memset(a, 0, sizeof(a)); for(int i = 0; i < n; i ++) { scanf("%d", &num0); a[500000 + num0] = 1; } // sort(a, a + n); int num = 0; // printf("%d\n", a[N - 1]); for(int i = N - 1; i >= 0; i --) { if(num == m) break; if(a[i]) { if(num != m - 1) printf("%d ", i - 500000); else printf("%d", i - 500000); num ++; } } printf("\n"); } return 0;}
0 0
- hdu1425 sort(哈希表)
- hdu1425 sort (朴素)
- HDU1425 - sort (简单题)
- hdu1425 sort
- HDU1425:sort
- HDU1425-sort
- HDU1425----sort
- hdu1425.sort
- HDU1425:sort
- HDU1425 sort
- HDU1425-sort
- HDU1425 sort
- HDU1425:sort(哈希思想!)
- hdu1425 sort (hash)
- hdu1425 sort 解题报告
- sort HDU1425 TLE?!
- HDU1425 sort【水题】
- hdu1425——sort
- AS插件-Android Layout ID Converter
- Accelerated tensor_toolbox version 1.0
- 1268 和为K的组合
- Android版股票K线图实现方案
- Jsp自定义标签
- hdu1425 sort(哈希表)
- HDU 5394 Trie in Tina Town
- Codeforces 660D Number of Parallelograms 【思维】
- hdu 1698 Just a Hook lazy线段树
- ubuntu软件源-sources.list
- nrf51822开发指导之静态密钥配对--在SDK9.0的ble_app_uart例程修改
- 数据库去重
- Git入门(一)简易的命令行入门教程:
- ubuntu15.10 3D桌面