Acdream 1099 calculates the k-th largest

Source: Internet
Author: User

Question Link

Yaoyao's k-th time limit: 10000/5000 ms (Java/others) memory limit: 512000/256000 KB (Java/others) submitstatisticnext problemproblem description

One day, Yao (tsyao), the cute girl, was bored and came to play with you. But you don't know what to play... After a while, the witty Yaoyao proposed: "Well, you saidNIntegersXIAnd then say a number at will.K, I can quickly express the numbersKA large number ."

Input

Two integers in row 1stN, KSeparated by spaces;

2nd rows haveNIntegers (the same number can appear, all are randomly generated), also separated by spaces.

0 <n ≤ 5*10 ^ 6, 0 <k ≤ n

1 ≤ Xi ≤ 10 ^ 8

Output KA large number. Sample Input
5 25 4 1 3 1
Sample output
4
In hint numbers such as 2, 2, and 1, the first digit is 2, the second digit is 2, and the third digit is 1.
Because N is too large, you need to use input hanging, and then quickly select O (n. 1a Accepted code:
1 /************************************** * *********************************** 2> File Name: kth. CPP 3> author: stomach_ache 4> mail: [email protected] 5> created time:, Saturday, August 02, 2014> propose: acdream 7 ************************************** * **********************************/8 // enter + quick selection of 9 # include <cmath> 10 # include <string> 11 # include <cstdio> 12 # include <fstream> 13 # include <CS Tring> 14 # include <iostream> 15 # include <algorithm> 16 using namespace STD; 17 18 int N, K; 19 int A [1, 5000002]; 20 21 int read () {22 int x = 0; 23 char CH = ''; 24 while (CH <'0' | ch> '9') CH = getchar (); 25 while (CH> = '0' & Ch <= '9') x = x * 10 + CH-'0', CH = getchar (); 26 return X; 27} 28 29 int sort (int l, int R) {30 if (L> = r) return a [l]; 31 int substring = A [(L + r) /2]; 32 int I = L, j = r; 33 (;) {34 while (I <J & A [I] <= cursor) I ++; 35 while (I <J & A [J]> = callback) j --; 36 if (I <j) Swap (A [I], a [J]); 37 Else break; 38 I ++; j --; 39} 40 swap (A [I], a [(L + r)/2]); 41 if (I = k) return a [I]; 42 if (I <k) return sort (I + 1, R); 43 else return sort (L, i-1); 44} 45 46 int main (void) {47 While (~ Scanf ("% d", & N, & K) {48 for (INT I = 1; I <= N; I ++) 49 A [I] = read (); 50 k = n-k + 1; 51 int ans = sort (1, N); 52 printf ("% d \ n ", ans); 53} 54 return 0; 55}

 

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.