Autor
|
Tema: problemas con la salida (Leído 3,465 veces)
|
+ 1 Oculto(s)
Desconectado
Mensajes: 298
un defecto se puede convertir en una virtud
|
este es el ejercicio 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
|
|
« Última modificación: 15 Junio 2016, 00:35 am por qwery.azc »
|
En línea
|
|
|
|
+ 1 Oculto(s)
Desconectado
Mensajes: 298
un defecto se puede convertir en una virtud
|
ya lo entendi cuando lo programe lo posteo
|
|
|
En línea
|
|
|
|
+ 1 Oculto(s)
Desconectado
Mensajes: 298
un defecto se puede convertir en una virtud
|
funciona bien import java.util.*; import java.io.*; public class Main { int max; 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(); } }
|
|
|
En línea
|
|
|
|
AlbertoBSD
Programador y
Moderador Global
Desconectado
Mensajes: 3.705
🏴 Libertad!!!!!
|
Hola veo que te gustan los programas de concursos de programacion, he participado en varios y la verdad son un excelente ejercicio para el cerebro. Todo eso y a contra reloj No vi el mensaje antes a esa hora estaba trabajando. Lo bueno que pudiste resolverlo. Saludos
|
|
|
En línea
|
|
|
|
+ 1 Oculto(s)
Desconectado
Mensajes: 298
un defecto se puede convertir en una virtud
|
gracias AlbertoBSD ahora tengo otra duda 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???
|
|
|
En línea
|
|
|
|
AlbertoBSD
Programador y
Moderador Global
Desconectado
Mensajes: 3.705
🏴 Libertad!!!!!
|
Hola el numero es la suma de 8 de los 64 numeros en el tablero la tarea es colocar a las reinas en el tablero de tal forma que cumpla con la condicion de que ninguna reina se ataque y sea el numero mas alto posible.
La idea sería si s posible buscar una formación o ul algorimo para colocar a las reinas y obtener la mayor suma.
Si gustas puedes abrir un topic por problema y los discutímos individualmente.
Sirve que les colocas un titulo mas descriptivo.
Saludos
|
|
« Última modificación: 15 Junio 2016, 15:44 pm por AlbertoBSD »
|
En línea
|
|
|
|
+ 1 Oculto(s)
Desconectado
Mensajes: 298
un defecto se puede convertir en una virtud
|
cuales son las reinas, lo hice diferente
mi idea fue sumar la diagonal de toda la matriz y creo que funciona pero nose
|
|
|
En línea
|
|
|
|
AlbertoBSD
Programador y
Moderador Global
Desconectado
Mensajes: 3.705
🏴 Libertad!!!!!
|
Ese es el problema tu tienes que colocar a las reinas son 8 y de hecho en la lectura dice las reglas son las mismas que en el ajedrez.
Otro detalle que los numeros no necesariamente van a estar en orden.
Saludos.
|
|
|
En línea
|
|
|
|
+ 1 Oculto(s)
Desconectado
Mensajes: 298
un defecto se puede convertir en una virtud
|
tengo otro problema interesante 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
|
|
|
En línea
|
|
|
|
|
|