HDU 1425 Sort (sorted)

Source: Internet
Author: User

SortTime limit:6000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 28997 Accepted Submission (s): 8796


Problem description gives you n integers, please output the number of the first m large in order from large to small.

Input each set of test data has two rows, the first row has two number n,m (0<n,m<1000000), the second row contains n each is different, and is in the interval [ -500000,500000] integer.

Output outputs the number of first m large for each set of test data, in order from large to small.

Sample Input
5 33-35 92 213-644

Sample Output
213 3HintHint  please submit with vc/vc++
#include <iostream> #include <stdio.h> #include <algorithm>using namespace Std;int a[1000010];void    Swap (int *a,int *b) {int T =*a;    *a=*b; *b=t;}    int partition (int a[],int l,int h) {int i=l;    int j=h+1;    int v=a[l];        while (true) {while (a[++i]>v) if (i==h) is break;        while (A[--J]&LT;V) if (h==l) break;        if (i>=j) break;    Swap (&a[i],&a[j]);    } swap (&a[l],&a[j]); return J;}    void Quick_sort (int a[],int l,int h) {if (h<=l) return;    int j=partition (A,L,H);    Quick_sort (A, L, j-1); Quick_sort (A, j+1, h);} int cmp (int a,int b) {return a>b;}    int main (int argc, char *argv[]) {int n,m;    Freopen ("1425.in", "R", stdin);        while (scanf ("%d%d", &n,&m) ==2) {for (int i=0;i<n;++i) scanf ("%d", &a[i]);         Sort (a,a+n,cmp);        Quick_sort (a,0,n-1);        if (m==1) printf ("%d\n", a[0]);           else{for (int i=0;i<m-1;++i) {     printf ("%d", a[i]);        } printf ("%d\n", a[m-1]); }} return 0;}



HDU 1425 Sort (sorted)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.