Anda di halaman 1dari 23

PROBLEMA A:

O Problema 3n + 1

espao com todos os trs nmeros em uma linha e com uma linha de sada para cada linha de entrada. Os inteiros i e j devem aparecer na sada na mesma ordem na qual aparecem na entrada e devem ser seguidos pelo tamanho do ciclo mximo (na mesma linha). Exemplo de Entrada 1 10 100 200 201 210 900 1000 Exemplo de Sada 1 10 20 100 200 125 201 210 89 900 1000 174

PROBLEMA A:
The 3n + 1 problem
Background Problems in Computer Science are often classified as belonging to a certain class of problems (e.g., NP, Unsolvable, Recursive). In this problem you will be analyzing a property of an algorithm whose classification is not known for all possible inputs. The Problem Consider the following algorithm: 1. input n 2. print n 3. if n = 1 then STOP 4. if n is odd then tex2html_wrap_inline44 5. else tex2html_wrap_inline46 6. GOTO 2 Given the input 22, the following sequence of numbers will be printed 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 It is conjectured that the algorithm above will terminate (when a 1 is printed) for any integral input value. Despite the simplicity of the algorithm, it is unknown whether this conjecture is true. It has been verified, however, for all integers n such that 0 < n < 1,000,000 (and, in fact, for many more numbers than this.) Given an input n, it is possible to determine the number of numbers printed (including the 1). For a given n this is called the cycle-length of n. In the example above, the cycle length of 22 is 16. For any two numbers i and j you are to determine the maximum cycle length over all numbers between i and j. The Input The input will consist of a series of pairs of integers i and j, one pair of integers per line. All integers will be less than 1,000,000 and greater than 0. You should process all pairs of integers and for each pair determine the maximum cycle length over all integers between and including i and j. You can assume that no operation overflows a 32-bit integer. The Output For each pair of input integers i and j you should output i, j, and the maximum cycle length for integers between and including i and j. These three numbers should be separated by at least one space with all three numbers on one line and with one line of output for each line of input.

The integers i and j must appear in the output in the same order in which they appeared in the input and should be followed by the maximum cycle length (on the same line). Sample Input 1 10 100 200 201 210 900 1000 Sample Output 1 10 20 100 200 125 201 210 89 900 1000 174

PROBLEMA B:
O Problema dos Blocos
Introduo Muitas reas da Cincia da Computao usam domnios abstratos e simples tanto para estudos analticos quanto empricos. Por exemplo, um recente estudo de IA em planejamento e robtica (STRIPS) usou um conjunto de blocos na qual um brao-rob realiza tarefas envolvendo a manipulao dos blocos. Neste problema voc ir modelar um simples conjunto de blocos sob certas regras e restries. Melhor do que determinar como alcanar um estado especfico, voc ir programar um brao robtico para responder a um conjunto limitado de comandos. O Problema O problema analisar uma srie de comandos que instruem o brao-rob sobre como manipular blocos que esto em uma mesa. Inicialmente existem n blocos na mesa (numerados de 0 a n-1) com o bloco bi adjacente ao bloco bi+1 para todos os 0 i < n-1 como mostra a figura abaixo:

Figura 1 - Conjunto inicial de blocos

Os comandos vlidos para o brao-rob que manipulam os blocos so: move a onto b onde a e b so nmeros dos blocos, colocar o bloco a sobre o bloco b e depois retornando qualquer bloco que est empilhado sobre os blocos a e b para suas posies iniciais. move a over b onde a e b so nmeros dos blocos, colocar o bloco a no topo da pilha contendo o bloco b, depois retornando qualquer bloco que est empilhado sobre o bloco a para suas posies iniciais. pile a onto b onde a e b so nmeros dos blocos, mover a pilha de bloco contendo o bloco a, e qualquer bloco que est empilhado sobre o bloco a, sobre o bloco b. Todos os blocos sobre o bloco b so movidos para suas posies iniciais antes que o movimento acontea. Os blocos empilhados sobre o bloco a mantm suas ordens quando movidos. pile a over b onde a e b so nmeros dos blocos, colocar a pilha de bloco contendo o bloco a, e qualquer bloco que est empilhado sobre o bloco a, no topo da pilha contendo o bloco b. Os blocos empilhados sobre o bloco a mantm suas ordens quando movidos. quit

7: 8: 9:

PROBLEMA B:
The Blocks Problem
Background Many areas of Computer Science use simple, abstract domains for both analytical and empirical studies. For example, an early AI study of planning and robotics (STRIPS) used a block world in which a robot arm performed tasks involving the manipulation of blocks. In this problem you will model a simple block world under certain rules and constraints. Rather than determine how to achieve a specified state, you will program a robotic arm to respond to a limited set of commands. The Problem The problem is to parse a series of commands that instruct a robot arm in how to manipulate blocks that lie on a flat table. Initially there are n blocks on the table (numbered from 0 to n-1) with block bi adjacent to block bi+1 for all 0 i < n-1 as shown in the diagram below:

Figura 2 - Initial blocks world

The valid commands for the robot arm that manipulates blocks are: move a onto b where a and b are block numbers, puts block a onto block b after returning any blocks that are stacked on top of blocks a and b to their initial positions. move a over b where a and b are block numbers, puts block a onto the top of the stack containing block b, after returning any blocks that are stacked on top of block a to their initial positions. pile a onto b where a and b are block numbers, moves the pile of blocks consisting of block a, and any blocks that are stacked above block a, onto block b. All blocks on top of block b are moved to their initial positions prior to the pile taking place. The blocks stacked above block a retain their order when moved. pile a over b where a and b are block numbers, puts the pile of blocks consisting of block a, and any blocks that are stacked above block a, onto the top of the stack containing block b. The blocks stacked above block a retain their original order when moved. quit terminates manipulations in the block world.

Any command in which a = b or in which a and b are in the same stack of blocks is an illegal command. All illegal commands should be ignored and should have no affect on the configuration of blocks. The Input The input begins with an integer n on a line by itself representing the number of blocks in the block world. You may assume that 0 < n < 25. The number of blocks is followed by a sequence of block commands, one command per line. Your program should process all commands until the quit command is encountered. You may assume that all commands will be of the form specified above. There will be no syntactically incorrect commands. The Output The output should consist of the final state of the blocks world. Each original block position numbered i (0 i < n where n is the number of blocks) should appear followed immediately by a colon. If there is at least a block on it, the colon must be followed by one space, followed by a list of blocks that appear stacked in that position with each block number separated from other block numbers by a space. Don't put any trailing spaces on a line. There should be one line of output for each block position (i.e., n lines of output where n is the integer on the first line of input). Sample Input 10 move 9 onto 1 move 8 over 1 move 7 over 1 move 6 over 1 pile 8 over 6 pile 8 over 5 move 2 over 1 move 4 over 9 quit Sample Output 0: 0 1: 1 9 2 4 2: 3: 3 4: 5: 5 8 7 6 6: 7: 8: 9:

PROBLEMA C:
Um N Muito Distante

Exemplo de Entrada 16 10 15 15 20 20 25 10 30 30 47 47 50 25 45 45 65 15 35 35 55 20 40 50 55 35 40 55 60 40 60 60 65 35 2 35 3 0 0 14 1 2 2 7 1 3 3 4 3 5 5 10 5 11 4 6 7 6 7 8 7 9 8 9 8 6 6 11 11 12 32 33 00 0 Exemplo de Sada Case 1: 5 nodes not reachable from node 35 with TTL = 2. Case 2: 1 nodes not reachable from node 35 with TTL = 3. Case 3: 8 nodes not reachable from node 1 with TTL = 1. Case 4: 5 nodes not reachable from node 1 with TTL = 2. Case 5: 3 nodes not reachable from node 3 with TTL = 2. Case 6: 1 nodes not reachable from node 3 with TTL = 3.

PROBLEMA C:
A Node Too Far
The Problem To avoid the potential problem of network messages (packets) looping around forever inside a network, each message includes a Time To Live (TTL) field. This field contains the number of nodes (stations, computers, etc.) that can retransmit the message, forwarding it along toward its destination, before the message is unceremoniously dropped. Each time a station receives a message it decrements the TTL field by 1. If the destination of the message is the current station, then the TTL field's value is ignored. However, if the message must be forwarded, and the decremented TTL field contains zero, then the message is not forwarded. In this problem you are given the description of a number of networks, and for each network you are asked to determine the number of nodes that are not reachable given an initial node and TTL field value. Consider the following example network:

If a message with a TTL field of 2 was sent from node 35 it could reach nodes 15, 10, 55, 50, 40, 20 and 60. It could not reach nodes 30, 47, 25, 45 or 65, since the TTL field would have been set to zero on arrival of the message at nodes 10, 20, 50 and 60. If we increase the TTL field's initial value to 3, starting from node 35 a message could reach all except node 45. Input and Output There will be multiple network configurations provided in the input. Each network description starts with an integer NC specifying the number of connections between network nodes. An NC value of zero marks the end of the input data. Following NC there will be NC pairs of positive integers. These pairs identify the nodes that are connected by a communication line. There will be no more than one (direct) communication line between any pair of nodes, and no network will contain more than 30 nodes. Following each network configuration there will be multiple queries as to how many nodes are not reachable given an initial node and TTL field setting. These queries are given as a pair of integers, the first identifying the starting node and the second giving the initial TTL field setting. The queries are terminated by a pair of zeroes. For each query display a single line showing the test case number (numbered sequentially from one), the number of nodes not reachable, the starting node number, and the initial TTL field setting. The sample input and output shown below illustrate the input and output format. Sample Input

16 10 15 15 20 20 25 10 30 30 47 47 50 25 45 45 65 15 35 35 55 20 40 50 55 35 40 55 60 40 60 60 65 35 2 35 3 0 0 14 1 2 2 7 1 3 3 4 3 5 5 10 5 11 4 6 7 6 7 8 7 9 8 9 8 6 6 11 11 12 32 33 00 0 Sample Output Case 1: 5 nodes not reachable from node 35 with TTL = 2. Case 2: 1 nodes not reachable from node 35 with TTL = 3. Case 3: 8 nodes not reachable from node 1 with TTL = 1. Case 4: 5 nodes not reachable from node 1 with TTL = 2. Case 5: 3 nodes not reachable from node 3 with TTL = 2. Case 6: 1 nodes not reachable from node 3 with TTL = 3.

PROBLEMA D:
Dgitos Romanos

PROBLEMA D:
Roman Digits
The Problem Many persons are familiar with the Roman numerals for relatively small numbers. The symbols i, v, x, l, and c represent the decimal values 1, 5, 10, 50, and 100 respectively. To represent other values, these symbols, and multiples where necessary, are concatenated, with the smaller-valued symbols written further to the right. For example, the number 3 is represented as iii, and the value 73 is represented as lxxiii. The exceptions to this rule occur for numbers having units values of 4 or 9, and for tens values of 40 or 90. For these cases, the Roman numeral representations are iv (4), ix (9), xl (40), and xc (90). So the Roman numeral representations for 24, 39, 44, 49, and 94 are xxiv, xxxix, xliv, xlix, and xciv, respectively. The preface of many books has pages numbered with Roman numerals, starting with i for the first page of the preface, and continuing in sequence. Assume books with pages having 100 or fewer pages of preface. How many i, v, x, l, and c characters are required to number the pages in the preface? For example, in a five page preface well use the Roman numerals i, ii, iii, iv, and v, meaning we need 7 i characters and 2 v characters. The Input The input will consist of a sequence of integers in the range 1 to 100, terminated by a zero. For each such integer, except the final zero, determine the number of different types of characters needed to number the prefix pages with Roman numerals. The Output For each integer in the input, write one line containing the input integer and the number of characters of each type required. The examples shown below illustrate an acceptable format. Sample Input 1 2 20 99 0 Sample Output 1: 1 i, 0 v, 0 x, 0 l, 0 c 2: 3 i, 0 v, 0 x, 0 l, 0 c 20: 28 i, 10 v, 14 x, 0 l, 0 c 99: 140 i, 50 v, 150 x, 50 l, 10 c

PROBLEMA E:
O Problema Ser responsvel pelo departamento de informtica da Agncia Internacional de Espionagem, voc convidado a escrever um programa que permitir que um espio codifique e decodifique suas mensagens. Voc pode assumir a mensagem de um espio tem no mximo 80 caracteres, e inclui todas as letras maisculas e minsculas do alfabeto mais o espao, e qualquer um dos seguintes caracteres: ! , . : ; ?

Abaixo est a tabela ASCII dos caracteres vlidos em uma mensagem: A 65 B 66 . . . Y 89 Z90 a b . . . y z 97 98 32 ! 33 "," 44 "." 46 ":" 58 , 59 ? 63

121 122

PROBLEMA E:
Encoder and Decoder
The Problem Being in charge of the computer department of the Agency of International Espionage, you are asked to write a program that will allow a spy to encode and decode their messages. You can assume a spy's message is at most 80 characters long, and it includes all the upper and lowercase letters of the alphabet plus the space, and any of the following characters: ! , . : ; ?

The following is an ASCII table of the valid characters in a message: A 65 B 66 . . . Y 89 Z90 a b . . . y z 97 98 32 ! 33 "," 44 "." 46 ":" 58 , 59 ? 63

121 122

The algorithm that you should use to encode messages is to take the ASCII value of each character in the message, starting with the last character in the message and ending with the first character in the message. You should then add on to the coded message this ASCII value written in reverse order. For example, if the ASCII value is 123, the encoded message should contain the string "321". There should be no spaces separating the numbers in the encoded message. Input and Output The input file consists of one or more lines with a normal (not encoded) or encoded message each. Output file must have the same number of lines with the corresponding encoded message or the decoded one, respectively. Sample Input abc 798999 Have a Nice Day ! Sample Output 998979 cba 332312179862310199501872379231018117927

PROBLEMA F:
Brazil 2014
O Problema Imagine que a fase de grupos na Copa do Mundo de Futebol no Brasil tenha terminado. 16 selees permanecem agora, entre as quais uma campe ser determinada pelo seguinte torneio:

Para cada possvel jogo A vs. B entre essas 16 selees, dada a probabilidade de que a seleo A ganhe da B. Isto (juntamente com o modo torneio mostrado acima) suficiente para calcular a probabilidade de que uma determinada seleo ganhe a Copa do Mundo. Por exemplo, se Germany tem 80% de chance de ganhar do Mexico, Romania tem 60% contra a contra a Croatia, Germany tem 70% contra Romania, e Germany tem 90% contra Croatia,