Cod sursa(job #1033488)

Utilizator miu_mik93FMI - Paduraru Miruna miu_mik93 Data 17 noiembrie 2013 00:18:27
Problema Statistici de ordine Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 1.16 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 i,n,k,v[3000001];
 
void statistici_ordin(int st,int dr)
{
	int min,max,mij;
	mij=v[(st+dr)/2];
	min=st;
	max=dr;
 
	while (min < max)
    {
		while (v[min] < mij)
			min++;
		while (v[max] > mij)
			max--;
 
		if (min <= max)
		{
			int aux = v[min];
			v[min] = v[max];
			v[max] = aux;
			min++;
			max--;
		}
      }
      if (k <= max && st < max)
		statistici_ordin (st, max);
      if (k >= min && min < dr)
		statistici_ordin (min, dr);
}
 
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]);
	}
	statistici_ordin(0, n-1);
	fprintf(g, "%d", v[k-1]);
	fclose(f); fclose(g);
	return 0;
}