Cod sursa(job #1033482)

Utilizator miu_mik93FMI - Paduraru Miruna miu_mik93 Data 17 noiembrie 2013 00:00:02
Problema Statistici de ordine Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 1.11 kb
#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;
}