sábado, 14 de abril de 2012

Problem B: Ultra-QuickSort

In this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the sequence is sorted in ascending order. For the input sequence
9 1 0 5 4 ,
Ultra-QuickSort produces the output
0 1 4 5 9 .
Your task is to determine how many swap operations Ultra-QuickSort needs to perform in order to sort a given input sequence.

The input contains several test cases. Every test case begins with a line that contains a single integer n < 500,000 -- the length of the input sequence. Each of the the following n lines contains a single integer 0 ≤ a[i] ≤ 999,999,999, the i-th input sequence element. Input is terminated by a sequence of length n = 0. This sequence must not be processed.

For every input sequence, your program prints a single line containing an integer number op, the minimum number of swap operations necessary to sort the given input sequence.

sábado, 24 de marzo de 2012

Solución al problema Moscas de la Omi Training Gate

Este problema ejemplifica el uso de la idea subyacente en el algoritmo de ordenación por conteo (también conocido como ordenación por cubetas). Una posible solución es la siguiente:

#include<stdio.h>
long n[60002],i,s,k,x,y,m;
int main(){
scanf("%ld",&k);
for(i=0;i<k;i++){
scanf("%ld %ld",&x,&y);
n[x]++;
n[y]--;
}
for(i=0;i<60001;i++){
s=s+n[i];
if(s>m)
m=s;
}
x=0;
y=0;
printf("%ld\n",m);
for(i=0;i<60001;i++){
if(s==m&&s+n[i]<m)
printf("%ld %ld ",x,i);
if(s<m&&s+n[i]==m)
x=i;
s=s+n[i];
}
}


miércoles, 21 de marzo de 2012

Concurso de la UVA Online Judge

Les dejo el link donde podran ver los problemas del concurso en linea de la UVA:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=13&page=show_contest&contest=296

Yo intente hacer el C y el H, pero mis algoritmos no eran eficientes, por lo que no me los aceptaron. Se los dejo como comentarios.

Si a alguien se le ocurre como resolverlos, o algun otro de la UVA, posteen su codigo.

sábado, 17 de marzo de 2012

Un número redivisible es aquel que es divisible entre su número de divisores positivos. Por ejemplo 1(1 divisor), 12(6 divisores) y 9(3 divisores) pero no 7(2 divisores) ni 16(5 divisores)

Escribe un programa que dados dos enteros l y h, diga cuántos números refactorizables hay entre l y h, inclusive.