HDU-1245(哈希表解法)

来源:互联网 发布:贷款app源码 编辑:程序博客网 时间:2024/06/08 19:44
题目名称: 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;}
原创粉丝点击