import java.util.Scanner;
/**
* Solucion al Problema: 1109 - False Ordering [http://lightoj.com/]
*
* @author BreakDark (Jhonny Monrroy)
* @version 1.0 13 ago. 2016
*/
// Accepted!!! xD
public class Main {
public static void main(String[] args) {
Scanner Lee; // para leer los datos de entrada
int t; // numero de casos
int n; // numero a evaluar
int vecDiv[]; // vector para almacenar cantidad de veces que es divisor
// cada indice
int vecNum[]; // numero de los valores que seran ordenados
int limite = 1001; // para el limite de las operaciones
// AQUI INICIA EL PROGRAMA
Lee = new Scanner(System.in);
// generamos el vector de num de divisores
vecDiv = new int[limite + 1];
vecNum = new int[limite + 1];
for (int i = 1; i <= limite; i++) {
for (int j = i; j <= limite; j += i) {
vecDiv[j]++;
}
vecNum[i] = i;
}
// ordenamos los valores por el metodo burbuja adecauado al problema
for (int i = 1; i < limite - 1; i++) {
for (int j = i + 1; j < limite; j++) {
int x = vecNum[j];
int y = vecNum[i];
if (vecDiv[x] < vecDiv[y] || (vecDiv[x] == vecDiv[y] && x > y)) {
int aux = vecNum[i];
vecNum[i] = vecNum[j];
vecNum[j] = aux;
}
}
}
// leemos los datos
t = Lee.nextInt();
for (int i = 1; i <= t; i++) {
n = Lee.nextInt();
System.out.println("Case " + i + ": " + vecNum[n]);
}
Lee.close();
}
}
Blog dedicado a la publicación de artículos, programas propios, traducciones de Roms de Nes, super Nes y mas, y alguno que otro artículo sobre tecnologia.
Thursday, September 15, 2016
Solucion al Problema: 1109 - False Ordering [http://lightoj.com/] con Java
Para ver el link del problema Click aqui
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment