andre_joy

导航

hdu 1425

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1425

题意:中文……

mark:qsor()简单水过。不过效率不是很高,985ms,可以用别的排序方法加快效率。

代码:

#include <stdio.h>
#include <stdlib.h>

int cmp(const void *a, const void *b)
{
    return *(int *)b - *(int *)a;
}

int a[1000010];

int main()
{
    int m,n,i;
    while(~scanf("%d%d", &n, &m))
    {
        for(i = 0; i < n; i++)
            scanf("%d",a+i);
        qsort(a, n, 4, cmp);
        for(i = 0; i < m; i++)
        {
            if(i) printf(" ");
            printf("%d", a[i]);
        }
        puts("");
    }
    return 0;
}

posted on 2012-07-01 14:04  andre_joy  阅读(275)  评论(0编辑  收藏  举报