Wednesday, March 28, 2012

Solución a 2017 - Hey, You're Not Marion Jones! [http://livearchive.onlinejudge.org]

Solución a 2017 - Hey, You're Not Marion Jones! [http://livearchive.onlinejudge.org]
El enunciado esta en el siguiente link enunciado

import java.util.Scanner;

/**
 * 2017 - Hey, You're Not Marion Jones! [http://livearchive.onlinejudge.org]
 * 
 * @author BreakDark
 * @version 1.0 beta
 */
// ACEPTADO!!! xD
public class Main {
 static byte funcionG[] = {1, 5, 7, 6, 2, 8, 3, 0, 9, 4};
 public static void main(String[] args) {
  Scanner Lee; // para ller los datos de entrada
  int n; // para el numero de casos
  String barcode; // para el codigo a leer
  String numBase10; // para el numero base 10
  String[] cifraSignificativa = {"athlete", "athlete", "reserve", "reserve", "judge", "judge", "staff", "staff", "press", "press"};

  // AQUI INICIA EL PROGRAMA!!!
  Lee = new Scanner(System.in);
  n = Lee.nextInt();
  while(n-- > 0){
   barcode = Lee.next();
   numBase10 = convertir(barcode);
   System.out.print(barcode + "/" + numBase10 + " is ");
   // verificamos si numBase10 es un ID valido
   if(esValido(numBase10))
    System.out.println("valid " + cifraSignificativa[numBase10.charAt(0) - '0'] + " id number");
   else
    System.out.println("invalid id number");
  }
 }
 /** Verifica si un ID es valido */
 private static boolean esValido(String numero) {
  // sacamos las funciones F
  int[] F = new int[8];
  byte i, j;
  for(i = 0, j = 7; i < 8; i++, j--)
   F[i] = funcionF(i, numero.charAt(j) - '0');
  // realizamos la funcionIporJ
  int producto = funcionIporJ(F[0], F[1]);
  for(i = 2; i < 8; i++)
   producto = funcionIporJ(producto, F[i]);
  if(producto == 0)
   return true;
  return false;
 }
 /** realiza la funcionIporJ */
 private static int funcionIporJ(int i, int j) {
  if(i < 5 && j < 5)
   return (i + j) % 5;
  if(i < 5 && j >= 5){
   if(i + (j - 5) < 0)
    return ((i + (j - 5)) + 5) % 5 + 5;
   return (i + (j - 5)) % 5 + 5;
  }
  if(i >= 5 && j < 5){
   if(((i - 5) - j) < 0)
    return (((i - 5) - j) + 5) % 5 + 5;
   return ((i - 5) - j) % 5 + 5;
  }
  if((i - j) < 0)
   return ((i - j) + 5) % 5;
  return (i - j) % 5;
 }
 /** realiza la funcionF */
 private static int funcionF(int i, int j) {
  if(i == 0)
   return j;
  else
   if(i == 1)
    return funcionG[j];
   else
    return funcionF(i - 1, funcionG[j]);
 }
 /** Convierte el numero base 5 a base 10 */
 private static String convertir(String cadena) {
  long r = 0;
  String r2;
  int i, j = 0;
  for(i = cadena.length() - 1; i >= 0; i--, j++){
   switch(cadena.charAt(i)){
    case 'V':
     r += (4 * Math.pow(5, j));
     break;
    case 'W':
     r += (3 * Math.pow(5, j));
     break;
    case 'X':
     r += (2 * Math.pow(5, j));
     break;
    case 'Y':
     r += (1 * Math.pow(5, j));
     break;
    default:
     r += 0;
     break;
   }
  }
  r2 = Long.toString(r);
  // completamos con ceros si es necesario
  while(r2.length() < 8)
   r2 = '0' + r2;
  return r2;
 }
}

Solución a 2015 - Bob's Bingo Bonanza [http://livearchive.onlinejudge.org]

Solución a 2015 - Bob's Bingo Bonanza [http://livearchive.onlinejudge.org]
El enunciado esta en el siguiente link enunciado

import java.util.BitSet;
import java.util.Scanner;

/**
 * 2015 - Bob's Bingo Bonanza [http://livearchive.onlinejudge.org]
 * 
 * @author BreakDark
 * @version 1.1 beta
 */
// ACEPTADO!!! xD
public class Main {
    public static void main(String[] args) {
        Scanner Lee; // para leer los datos de entrada
        BitSet modTarjeta = new BitSet(25); // para el modelo de la tarjeta
        byte n; // para el numero de tarjetas
        int game = 1; // para el numero de juego
        BitSet[] tarjeta = new BitSet[100];
        byte i, j; // para los bucles
        String linea; // para leer una linea

        // AQUI INICIA EL PROGRAMA
        Lee = new Scanner(System.in);
        for(i = 0; i < 100; i++)
            tarjeta[i] = new BitSet(76);
        do{
            // leemos el modelo
            j = 0;
            linea = "";
            modTarjeta.clear();
            for(i = 0; i < 5; i++)
                linea += Lee.next();
            for(i = 0; i < linea.length(); i++){
                if(linea.charAt(i) == 'X')
                    modTarjeta.set(i);
            }
            // leemos n
            n = Lee.nextByte();
            if(n > 0){
                if(game > 1)
                    System.out.println(); // linea en blanco
                // llenamos las tarjetas
                for(i = 0; i < n; i++){
                    tarjeta[i].clear();
                    for(j = 0; j < 25; j++){
                        if(modTarjeta.get(j))
                            tarjeta[i].set(Lee.nextByte());
                        else
                            Lee.nextByte();
                    }
                }
                System.out.println("Game " + game++);
                // procesamos la informacion
                procesar(tarjeta, n);
            }
        } while(n > 0);
    }
    /** procedimiento que hace todo el trabajo */
    private static void procesar(BitSet[] tarjeta, byte n) {
        byte i, j;
        // buscamos en todos los juegos de tarjetas
        for(i = 1; i < n; i++){
            // recorremos las tarjetas
            for(j = 0; j < i; j++){
                // preguntamos si tienen numeros comunes
                if(tarjeta[i].equals(tarjeta[j])){
                    System.out.println("Card " + (i + 1) + " is equivalent to card " + (j + 1));
                    break;
                }
            }
        }
    }
}

Tuesday, March 13, 2012

ATENCION SOLO PARA 143

ATENCION SOLO PARA 143
La pagina para descargas de material esta alojada en el siguiente blog
http://breakdark143.blogspot.com/
SALUDOS

Thursday, March 01, 2012