Pagini recente » Cod sursa (job #1094945) | Cod sursa (job #2691884) | Cod sursa (job #1796291) | Cod sursa (job #1093656) | Cod sursa (job #1033482)
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <assert.h>
#include <time.h>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <queue>
#include<cstdlib>
using namespace std;
#define MAXN 3000001
#define radical3 1.7320508075
#define MAXDIFF 2000000000
#define PI 3.141592653
double eps = 1e-3;
int n, k, v[MAXN];
void statistic (int li , int ls)
{
int min = li, max = ls;
int mid = v[( li + ls ) / 2];
while ( min < max )
{
while (v[min] < mid)
min++;
while (v[max] > mid)
max--;
if (min <= max)
{
int aux = v[min];
v[min] = v[max];
v[max] = aux;
min++; max--;
}
if ( k <= max && li < max )
statistic(li, max);
if ( k >= min && ls > min )
statistic(min, ls);
}
}
int main()
{
FILE *f = fopen("sdo.in", "r");
FILE *g = fopen("sdo.out", "w");
fscanf(f, "%d %d", &n, &k);
for (int i = 0; i < n; i++)
{
fscanf(f, "%d", &v[i]);
}
statistic(0, n-1);
fprintf(g, "%d", v[k-1]);
fclose(f); fclose(g);
return 0;
}