Nine degrees OJ 1034 looking for a millionaire

Source: Internet
Author: User

Topic 1034: Looking for a Millionaire

time limit:1 seconds

Memory limit:32 MB

Special question: No

submitted:5168

Resolution:2075

Title Description:
Zhejiang Tongxiang Wu Town A total of n individuals, please find the town of the former m monopoly.
Input:
The input contains multiple sets of test cases.
Each use case first contains 2 integers n (0<n<=100000) and M (0<m<=10), Where: N is the number of people in town, M is the number of millionaires that need to be found, and the next line is to enter the wealth value of N people in the town.
N and m at 0 indicate the end of the input.
Output:
please output wuzhen former M monopoly property number, property of the row front, if the monopoly less than m, then all output, each group of output accounted for a row.
Sample input:
3 12 5-15 31 2 3 4 50 0
example Output:
55 4 3 
#include <stdio.h> #include <string.h> int a[100010];int aux[100010];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 (1) {while (a[++i]>v) if (i==h) is break;        while (A[--J]&LT;V) if (j==l) break;        if (i>=j) break;    Swap (&a[i],&a[j]);    } swap (&a[l],&a[j]); return J;}    void Q_sort (int a[], int l,int h) {if (l>=h) return;    int j=partition (A,L,H);    Q_sort (a,l,j-1); Q_sort (a,j+1,h);}    void merge (int a[],int l,int mid,int h) {int i=l;    int j=mid+1;    for (int k=l;k<=h;++k) aux[k]=a[k];        for (int k=l;k<=h;++k) {if (i>mid) a[k]=aux[j++];        else if (j>h) a[k]=aux[i++];        else if (Aux[i]>aux[j]) a[k]=aux[i++];    else a[k]=aux[j++];    }}void m_sort (int a[],int l,int h) {if (h<=l) return;    int mid=l+ (H-L)/2;    M_sort (A, L, mid);    M_sort (A,MID+1,H); Merge (a,l,mid,h);} int main (int argc, CHAR *argv[]) {int n,m;        while (scanf ("%d%d", &n,&m) ==2) {memset (a,0,sizeof (a));        if (n==0&&m==0) return 0;        for (int i=0;i<n;++i) scanf ("%d", &a[i]);        M_sort (a,0,n-1); for (int i=0;;            ++i) {if (m) printf ("%d", a[i]);            m--;            if (m) printf ("");        if (m==0) break;     } printf ("\ n"); } return 0;} /************************************************************** problem:1034 User:kirchhoff language:c Resu lt:accepted time:30 Ms memory:1696 kb****************************************************************/



Nine degrees OJ 1034 looking for a millionaire

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.