当前位置: 代码迷 >> 综合 >> HDU-1245(哈希表解法)
  详细解决方案

HDU-1245(哈希表解法)

热度:24   发布时间:2023-11-23 12:59:47.0
题目名称: sort
题目链接: https://vjudge.net/problem/HDU-1425
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 500000;
int hashMap[MAXN<<1|1];int main()
{int n, m;while(scanf("%d%d", &n, &m) != EOF){int i;memset(hashMap, 0, sizeof(hashMap));int key = 0;for(i = 0; i < n; ++i){scanf("%d", &key);hashMap[MAXN + key] = 1;}int flag = 0;for(i = MAXN<<1; i >= 0 && m > 0; i--){if(!hashMap[i])continue;if(flag)cout << ' ' << i - MAXN;else cout << i - MAXN;flag = 1;m--;}cout << endl;}return 0;
}