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]<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)