hdu 1280 计数排序

来源:互联网 发布:php https curl 编辑:程序博客网 时间:2024/06/06 00:34

http://acm.hdu.edu.cn/showproblem.php?pid=1280


#include <stdio.h>#include <string.h>#define N 10001int n,m;int a[N],cc[N];int main(){    while(scanf("%d%d",&n,&m) != EOF)    {        memset(cc,0,sizeof(cc));        int i,j;        int max = 0;        for(i = 0; i < n; ++i)        {            scanf("%d",&a[i]);            if(max < a[i])                max = a[i];            for(j = 0; j < i; ++j)                cc[a[i] + a[j]]++;        }        for(j = 0,i = (max<<1); m;--i)            while(cc[i]-- && m)            {                --m;                a[j++] = i;            }        for(i = 0; i < j-1; ++i)///额。。。PE了一次。。。            printf("%d ",a[i]);        printf("%d\n",a[i]);    }    return 0;}


原创粉丝点击