fjnu 1761 star55的难题

来源:互联网 发布:jdbc怎么连接数据库 编辑:程序博客网 时间:2024/05/17 03:15
 

Description

去年新年的时候,在新区开始了一场acm比赛,记得其中有一题是这样的:

任给N个数,求从小到大排序后第S个数是多少

Input

输入N,S(0<N<=2000000,0<S<=2000000),其中N为数的个数,找出排在第S的数。
接着输入N个数X(0<=X<100)。

Output

输入排序后排在第S个位置的数

Sample Input

10 51 1 62 81 30 77 44 32 94 57 

 

Sample Output

44

 

Hint

排序完为:1 1 30 32 44 57 62 77 81 94
第5个数是44。

KEY:很明显是考算法,所以要注意时间限制,用<algorithm> sort();

Source:

#include 
<stdio.h> 
#include 
<algorithm> 

using namespace std; 

int a[2000000]; 
int main() 

//freopen("fjnu_1761.in","r",stdin);
int n, s,i; 
scanf(
"%d%d",&n,&s);
for( i = 0 ; i < n ; i++
scanf(
"%d",&a[i]); 
sort(a,a
+n); 
printf(
"%d ",a[s-1]); 
return 0;
}