返回信息流//#include <stdio.h>
//#include <stdlib.h>
#include <iostream>
using namespace std;
//#include <algorithm>
//#include <ctime>
//#include <cstdlib>
//#include <iostream>
//using namespace std;
/*
void InsertSort(int r[],int n)
{
int j;
for (int i = 2;i <= n;i ++)
{
r[0] = r[i];
for (j = i-1;r[0] > r[j];j --)
r[j+1]=r[j];
r[j+1]=r[0];
}
};
*/
void SelectSort(int r[],int n)
{
int index;
for (int i = 1;i < n;i ++)
{
index = i;
for (int j = i + 1;j <= n;j ++)
if (r[j] > r[index])
index = j;
if (index != i)
swap(r[i],r[index]);
}
};
/*
void shuffle(int* a, int size)
{
for (int i=0; i<size; a[i]=i, i++);
for (int i=0; i<size; i++)
swap(a[i], a[i+rand()%(size-i)]);
}
*/
main()
{
int Max[50000];
int M,N;
int i,j;
int Mth;
// srand(time(NULL));
// shuffle(Max, 50000);
// freopen("in.txt", "w", stdout);
// cout << "50000 10000" << endl;
// for (int i=0;i<50000; i++)
// cout << Max[i] << " ";
// cout << endl;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// clock_t start = clock();
scanf("%d %d",&N,&M);
for (i = 1;i <= N;i ++)
scanf("%d",&Max[i]);
// InsertSort(Max,N);
SelectSort(Max,N);
Mth = Max[1];
for (i = 2,j = 1;i <= N,j!= M;i ++)
if (Max[i] < Mth)
{
Mth = Max[i];
j++;
}
printf("%d",Mth);
// clock_t end = clock();
// cout << endl << end - start << " ms" << endl;
// system("pause");
// return 0;
}
这是一条镜像帖。来源:北邮人论坛 / cpp / #34075同步于 2009/12/23
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
acm那个网站上的一道题,他说output time limit exceed,请教一
cfy744674198
2009/12/23镜像同步10 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
Description
Now, there are a list of N numbers. Your job is to find the Mth largest number X. (there are M-1 numbers >= X)
Input
There are 2 lines for the case.
In the first line, there are 2 numbers N and M.( M < N )
In the second line, there are N numbers.( all numbers are intger)
N <= 500000.
Output
you should output one number which is the Mth largest number in the list.
Sample Input
5 1
2 4 0 4 4
Sample Output
4
这是那道题的题目
【 在 Raiden 的大作中提到: 】
: 到底是output limit exceed还是time limit exceed啊
: 后者的话,优化算法吧
北邮ACM的网址是什么?同学,能发给我吗?谢谢