Pagini recente » Cod sursa (job #1284315) | Cod sursa (job #1876347) | Cod sursa (job #755944) | Cod sursa (job #1740160) | Cod sursa (job #502904)
Cod sursa(job #502904)
/*
Problem 1 - Compounds
In a chemical analysis laboratory, there are N chemical compounds.
In the interest of avoiding accidents or the alteration of the compounds,
each compound has to be kept in special temperature conditions. For each chemical compound x, we know the
[min,max] interval in which it can be kept without the risk of alteration. The chemicals are all kept in
refrigerators. Each refrigerator can be set to a certain (constant) temperature (expressed as an integer
representing the temperature in Celsius degrees).
Write a program which determines the minimum number of refrigerators necessary for storing the chemical
compounds without the risk of altering them.
*/
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#define _DEBUG_ 1
int n;
int *x;
int *y;
const char *fisier_in = "algsort.in";
const char *fisier_out = "algsort.out";
void quick_sort(int left, int right, int *x)
{
int i = left;
int j = right;
int middle = x[(i + j) >> 1];
do
{
while (x[i] < middle) ++i;
while (x[j] > middle) --j;
if (i <= j)
{
static int temp;
temp = x[i];
x[i] = x[j];
x[j] = temp;
++i;
--j;
}
} while (i <= j);
if (i < right) quick_sort(i, right, x);
if (j > left) quick_sort(left, j, x);
}
int main()
{
freopen(fisier_in, "r", stdin);
freopen(fisier_out, "w", stdout);
scanf("%d", &n);
x = (int *)calloc(n+1, sizeof(int));
for (int i = 1; i <= n; ++i)
scanf("%d", &x[i]);
quick_sort(1, n, x);
for (int i = 1; i <=n; ++i)
printf("%d ", x[i]);
return 0;
}