Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Mensajes - + 1 Oculto(s)

#191
Java / Re: problemas con la salida
16 Junio 2016, 00:59 AM
tengo otro problema interesante
Código (xml) [Seleccionar]

The government of Nova Mareterrania requires that various legal documents have stamps attached to them so that the government can derive revenue from them. In terms of recent legislation, each class of document is limited in the number of stamps that may be attached to it. The government wishes to know how many different stamps, and of what values, they need to print to allow the widest choice of values to be made up under these conditions. Stamps are always valued in units of $1.

This has been analysed by government mathematicians who have derived a formula for n(h,k), where h is the number of stamps that may be attached to a document, k is the number of denominations of stamps available, and n is the largest attainable value in a continuous sequence starting from $1. For instance, if h=3, k=2 and the denominations are $1 and $4, we can make all the values from $1 to $6 (as well as $8, $9 and $12). However with the same values of h and k, but using $1 and $3 stamps we can make all the values from $1 to $7 (as well as $9). This is maximal, so n(3,2) = 7.

Unfortunately the formula relating n(h,k) to h, k and the values of the stamps has been lost--it was published in one of the government reports but no-one can remember which one, and of the three researchers who started to search for the formula, two died of boredom and the third took a job as a lighthouse keeper because it provided more social stimulation.

The task has now been passed on to you. You doubt the existence of a formula in the first place so you decide to write a program that, for given values of h and k, will determine an optimum set of stamps and the value of n(h,k).

Input

Input will consist of several lines, each containing a value for h and k. The file will be terminated by two zeroes (0 0). For technical reasons the sum of h and k is limited to 9. (The President lost his little finger in a shooting accident and cannot count past 9).

Output

Output will consist of a line for each value of h and k consisting of the k stamp values in ascending order right justified in fields 3 characters wide, followed by a space and an arrow (->) and the value of n(h,k) right justified in a field 3 characters wide.

Sample input

3 2
0 0
Sample output

  1  3 ->  7


#192
Java / Re: problemas con la salida
15 Junio 2016, 19:19 PM
cuales son las reinas, lo hice diferente

mi idea fue sumar la diagonal de toda la matriz y creo que funciona pero nose
#193
Java / Re: problemas con la salida
15 Junio 2016, 15:20 PM
gracias AlbertoBSD
ahora tengo otra duda

Código (xml) [Seleccionar]

The Sultan of Nubia has no children, so she has decided that the country will be split into up to k separate parts on her death and each part will be inherited by whoever performs best at some test. It is possible for any individual to inherit more than one or indeed all of the portions. To ensure that only highly intelligent people eventually become her successors, the Sultan has devised an ingenious test. In a large hall filled with the splash of fountains and the delicate scent of incense have been placed k chessboards. Each chessboard has numbers in the range 1 to 99 written on each square and is supplied with 8 jewelled chess queens. The task facing each potential successor is to place the 8 queens on the chess board in such a way that no queen threatens another one, and so that the numbers on the squares thus selected sum to a number at least as high as one already chosen by the Sultan. (For those unfamiliar with the rules of chess, this implies that each row and column of the board contains exactly one queen, and each diagonal contains no more than one.)

Write a program that will read in the number and details of the chessboards and determine the highest scores possible for each board under these conditions. (You know that the Sultan is both a good chess player and a good mathematician and you suspect that her score is the best attainable.)

Input

Input will consist of k (the number of boards), on a line by itself, followed by k sets of 64 numbers, each set consisting of eight lines of eight numbers. Each number will be a positive integer less than 100. There will never be more than 20 boards.

Output

Output will consist of k numbers consisting of your k scores, each score on a line by itself and right justified in a field 5 characters wide.

Sample input

1
1  2  3  4  5  6  7  8
9 10 11 12 13 14 15 16
17 18 19 20 21 22 23 24
25 26 27 28 29 30 31 32
33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48
48 50 51 52 53 54 55 56
57 58 59 60 61 62 63 64
Sample output

  260




como obtener 260???


#194
Java / Re: problemas con la salida
15 Junio 2016, 03:02 AM
funciona bien :)

Código (java) [Seleccionar]


import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        int max;
        String cadenas;
        int aux = 0;
        int au2 = 0;

        while ((cadenas = bf.readLine()) != null) {
            int cant = Integer.parseInt(cadenas);
            ArrayList<Integer> coleccion = new ArrayList<>();
            max = (int) Math.ceil(Math.pow(10, cant / 2));
            for (int i = 0; i < Math.pow(max, 2); i++) {
                aux = (int) (i / max);
                au2 = (int) (i % max);
                if (i == Math.pow(aux + au2, 2)) {
                    coleccion.add(i);
                }
            }
            for (int i = 0; i < coleccion.size(); i++) {
               
                System.out.printf("%0" + cant + "d%n", coleccion.get(i));
            }
            }
        bf.close();
        System.exit(0);
    }
}
#195
Java / Re: problemas con la salida
15 Junio 2016, 00:42 AM
ya lo entendi cuando lo programe lo posteo
#196
Java / problemas con la salida
14 Junio 2016, 22:54 PM
este es el ejercicio
Código (xml) [Seleccionar]


Quirksome Squares

The number 3025 has a remarkable quirk: if you split its decimal representation in two strings of equal length (30 and 25) and square the sum of the numbers so obtained, you obtain the original number:

displaymath26

The problem is to determine all numbers with this property having a given even number of digits.

For example, 4-digit numbers run from 0000 to 9999. Note that leading zeroes should be taken into account. This means that 0001 which is equal to  tex2html_wrap_inline28 is a quirksome number of 4 digits. The number of digits may be 2,4,6 or 8. Although maxint is only 32767 and numbers of eight digits are asked for, a well-versed programmer can keep his numbers in the range of the integers. However efficiency should be given a thought.

Input

The input of your program is a textflle containing numbers of digits (taken from 2,4,6,8), each number on a line of its own.

Output

The output is a textfile consisting of lines containing the quirksome numbers (ordered according to the input numbers and for each input number in increasing order).

Warning: Please note that the number of digits in the output is equal to the number in the corresponding input line : leading zeroes may not be suppressed.

Sample Input

2
2
Sample Output

00
01
81
00
01
81


no entiendo como obtener esa salida, ayuda

no entiendo como obtener el output 00
01
81
00
01
81???
es el ejercicio 256 del juez uva de la universidad de valladolid
#197
Código (java) [Seleccionar]


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
*
* @author qwery,azc
*/
public class RadixSort {
   
    public ArrayList<Integer> radixSort(ArrayList<Integer> entryData) {
        int max = Collections.max(entryData);
        max = cantidadDigitos(max);
        Map<Integer, ArrayList> regid = new HashMap();
        int dataAux = 0;
        int digMenorSig = 0;
        int porciento = 10;
        ArrayList<Integer> lista = new ArrayList<>();
        ArrayList<Integer> copiaSort = new ArrayList<>();
        for (int i = 0; i < max; i++) {
           
            porciento *= 10;
            for (int j = 0; j < entryData.size(); j++) {
                dataAux = entryData.get(j);
                digMenorSig = dataAux % 10;
                lista.add(dataAux);
                regid.put(digMenorSig, lista);
                dataAux = dataAux / porciento;
            }
           
            for (Map.Entry<Integer, ArrayList> entry : regid.entrySet()) {
                Integer key = entry.getKey();
                ArrayList<Integer> value = entry.getValue();
                for (int j = 0; j < value.size(); j++) {
                    copiaSort.add(value.get(j));
                }
               
            }
            entryData=copiaSort;
           
        }
        for (int i = 0; i < entryData.size(); i++) {
            System.err.println(entryData.get(i));
        }
        //System.out.println("max " + max);
        return null;
    }
   
    public int cantidadDigitos(int data) {
        int res = 0;
        while (data > 0) {
            data = data / 10;
            res++;
        }
        return res;
    }
   
    public static void main(String args[]) {
        RadixSort r = new RadixSort();
        ArrayList<Integer> a = new ArrayList();
        a.add(34);
        a.add(27);
        a.add(38);
        r.radixSort(a);
       
    }
}





no funciona... no se en que estoy fallando ayuda...
#198
Java / Re: StringBuilder vs String ( JAVA )
13 Junio 2016, 01:32 AM
entonces StringBuilder es un contenedor

en que casos usar String y en que casos usar String builder?
#199
Java / StringBuilder vs String ( JAVA )
12 Junio 2016, 23:48 PM
por que cuando utilizo StringBuilder el tiempo de ejecucion disminuye respecto al utilizar String

alguna explicacion?
#200
Java / Re: app que te reconozca
10 Junio 2016, 01:48 AM
hola comunidad
me refiero a auntentificacion de usuarios
como harian cuando el usuario se equivoque al escribir por decir en una o dos letras y que el sistema te pueda corregir e ingreses al sistema(loguees) perfectamente?
por ejemplo un usuario se equivoca casi siempre en la misma letra que el sistema le pueda corregir e ingrese

pero si se equivoca en una letra distinta entonces que no le permita

algun algoritmo que me puedan aconsejar?
algun otro parametro a tomar en cuenta?