hdu 1425 sort hash

来源:互联网 发布:批量查询域名 编辑:程序博客网 时间:2024/06/03 21:43

sort

Time Limit: 6000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 52678 Accepted Submission(s): 14898

Problem Description
给你n个整数,请按从大到小的顺序输出其中前m大的数。

Input
每组测试数据有两行,第一行有两个数n,m(0

#include<cstdio>#include<iostream>#include<algorithm>#include<cmath>#include<cstring>using namespace std;int b[1000005];int main(){    int n,m;    while(~scanf("%d%d",&n,&m))    {        memset(b,0,sizeof(b));        int a;        for(int i=0; i<n; i++)        {           scanf("%d",&a);            b[a+500000]=1;        }        for(int i=1000001; m>0; i--)        {            if(b[i])            {                printf("%d",i-500000);                if(m>1)                    printf(" ");                else                    puts("");                m--;            }        }    }}
原创粉丝点击