• Nenhum resultado encontrado

Sample Input Output Input A - Bicoloring

N/A
N/A
Protected

Academic year: 2022

Share "Sample Input Output Input A - Bicoloring"

Copied!
8
0
0

Texto

(1)

A - Bicoloring

In 1976 the ``Four Color Map Theorem" was proven with the assistance of a computer. This theorem states that every map can be colored using only four colors, in such a way that no region is colored using the same color as a neighbor region.

Here you are asked to solve a simpler similar problem. You have to decide whether a given arbitrary connected graph can be bicolored. That is, if one can assign colors (from a palette of two) to the nodes in such a way that no two adjacent nodes have the same color. To simplify the problem you can assume:

• no node will have an edge to itself.

• the graph is nondirected. That is, if a nodeais said to be connected to a node b, then you must assume thatb is connected to a.

• the graph will be strongly connected. That is, there will be at least one path from any node to any other node.

Input

The input consists of several test cases. Each test case starts with a line containing the number n( 1 < n < 200) of different nodes. The second line contains the number of edges l. After this, llines will follow, each containing two numbers that specify an edge between the two nodes that they represent. A node in the graph will be labeled using a number a(

).

An input with n= 0 will mark the end of the input and is not to be processed.

Output

You have to decide whether the input graph can be bicolored or not, and print it as shown below.

Sample Input

3 3 0 1 1 2 2 0 9 8 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0

(2)

Sample Output

NOT BICOLORABLE.

BICOLORABLE.

B - Exact Sum

Peter received money from his parents this week and wants to spend it all buying books.

But he does not read a book so fast, because he likes to enjoy every single word while he is reading. In this way, it takes him a week to finish a book.

As Peter receives money every two weeks, he decided to buy two books, then he can read them until receive more money. As he wishes to spend all the money, he should choose two books whose prices summed up are equal to the money that he has. It is a little bit difficult to find these books, so Peter asks your help to find them.

Input

Each test case starts with 2 ≤ N ≤ 10000, the number of available books. Next line will have Nintegers, representing the price of each book, a book costs less than1000001.

Then there is another line with an integerM, representing how much money Peter has.

There is a blank line after each test case. The input is terminated by end of file (EOF).

Output

For each test case you must print the message: Peter should buy books whose prices are i and j., whereiandjare the prices of the books whose sum is equal do M andi ≤ j.

You can consider that is always possible to find a solution, if there are multiple solutions print the solution that minimizes the difference between the prices iandj. After each test case you must print a blank line.

Sample Input

2 40 40 80 5

10 2 6 8 4 10

(3)

Sample Output

Peter should buy books whose prices are 40 and 40.

Peter should buy books whose prices are 4 and 6.

C - Add bricks in the wall

The Problem

This in not "another brick in the wall", it's just a matter of adding numbers. Suppose you have a wall with the shape of a triangle, like the one shown below. The wall has 9rows and rowihas exactly ibricks, considering that top row is the first one and bottom row is the ninth. Some bricks are labeled with a number and other ones are blank. Notice that labeled bricks appear only on odd rows and they occupy odd positions within the row. The problem you must solve is finding a suitable number for each blank brick taking into account one simple rule: the number of a brick is obtained by adding the numbers of the two bricks below it. Obviously, this rule does not apply to the ninth row. Numbers are supposed to be integers.

The Input

The first line of the input contains an integer N, indicating the number of test cases. This line is followed by the lines corresponding to the test cases. Each test case is described in five lines. These five lines correspond to odd rows of the wall, from top to bottom, as described above. Line icontains the numbers corresponding to odd bricks on row i of the wall (that is, non blank bricks), enumerated from left to right and separated with a single space. It is supposed that each test case is correct, that is, there exists a solution to the problem that the case describes.

(4)

The Output

For each test case, the output should consist of nine lines describing the numbers of all bricks of the wall. So, line i should contain the numbers corresponding to the ibricks on row i of the wall, enumerated from left to right and separated by a single space.

Sample Input

Here we have an example with two test cases. The first one corresponds to the wall depicted above.

2 255 54 67 10 18 13 3 3 5 2 2 1 2 1 1 256

64 64 16 16 16 4 4 4 4 1 1 1 1 1

Sample Output

255 121 134 54 67 67 23 31 36 31 10 13 18 18 13 5 5 8 10 8 5 3 2 3 5 5 3 2 2 1 1 2 3 2 1 1 2 0 1 0 2 1 1 0 1 256

128 128 64 64 64 32 32 32 32 16 16 16 16 16 8 8 8 8 8 8 4 4 4 4 4 4 4 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1

(5)

D - QWERTY

A common typing error is to place the hands on the keyboard one row to the right of the correct position. So "Q" is typed as "W" and "J" is typed as "K" and so on. You are to decode a message typed in this manner.

Input consists of several lines of text. Each line may contain digits, spaces, upper case letters (except Q, A, Z), or punctuation shown above [except back-quote (`)]. Keys labelled with words [Tab, BackSp, Control, etc.] are not represented in the input. You are to replace each letter or punction symbol by the one immediately to its left on the QWERTY keyboard shown above. Spaces in the input should be echoed in the output.

Sample Input

O S, GOMR YPFSU/

Output for Sample Input

I AM FINE TODAY.

E - Ant on a Chessboard

Background

One day, an ant called Alice came to an M*M chessboard. She wanted to go around all the grids. So she began to walk along the chessboard according to this way: (you can assume that her speed is one grid per second)

At the first second, Alice was standing at (1,1). Firstly she went up for a grid, then a grid to the right, a grid downward. After that, she went a grid to the right, then two grids upward, and then two grids to the left…in a word, the path was like a snake.

For example, her first 25 seconds went like this:

( the numbers in the grids stands for the time when she went into the grids) 25 24 23 22 21

10 11 12 13 20

(6)

9 8 7 14 19

2 3 6 15 18

1 4 5 16 17

5 4 3 2 1

1 2 3 4 5

At the 8thsecond , she was at (2,3), and at 20thsecond, she was at (5,4).Your task is to decide where she was at a given time. (you can assume that M is large enough)

Input

Input file will contain several lines, and each line contains a number N(1<=N<=2*10^9), which stands for the time. The file will be ended with a line that contains a number 0.

Output

For each input situation you should print a line with two numbers (x, y), the column and the row number, there must be only a space between them.

Sample Input

8 20 25 0

Sample Output

2 3 5 4 1 5

(7)

F - Interpreter

A certain computer has 10 registers and 1000 words of RAM. Each register or RAM location holds a 3-digit integer between 0 and 999. Instructions

are encoded as 3-digit integers and stored in RAM. The encodings are as follows:

• 100 meanshalt

• 2dn meansset register d to n (between 0 and 9)

• 3dn meansadd n to register d

• 4dn meansmultiply register d by n

• 5ds meansset register d to the value of register s

• 6ds meansadd the value of register s to register d

• 7ds meansmultiply register d by the value of register s

• 8da meansset register d to the value in RAM whose address is in register a

• 9sa meansset the value in RAM whose address is in register a to the value of register s

• 0ds meansgoto the location in register d unless register s contains 0

All registers initially contain 000. The initial content of the RAM is read from standard input.

The first instruction to be executed is at RAM address 0. All results are reduced modulo 1000.

Input

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, andthere is also a blank line between two consecutive inputs.

The input to your program consists of up to 1000 3-digit unsigned integers, representing the contents of consecutive RAM locations starting at 0. Unspecified RAM locations are initialized to 000.

Output

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.

The output from your program is a single integer: the number of instructions executed up to and including thehaltinstruction. You may assume that the program does halt.

Sample Input

1 299 492 495 399 492 495

(8)

399 283 279 689 078 100 000 000 000

Sample Output

16

Referências

Documentos relacionados

A Diretoria de Risco possui a responsabilidade (a) pelo controle de risco das carteiras de valores mobiliários e fundos de investimentos sob gestão da Gestora; e (b) por

RF 4.3.2 Quando um SIGAD exportar os documentos e dossiês/processos de uma classe para executar uma ação de transferência ou recolhimento, tem que ser capaz de exportar todos

Embora não seja pacífico na doutrina, trataremos da conciliação como método autocompositivo, considerando os sujeitos envolvidos e a dinâmica processual utilizada, que

xyli e não detectado nos demais tratamentos, nem mesmo naquele onde todas as bactérias foram inoculadas (Tabela 2).. Incidência de Leifsonia xyli subsp. gramas de

8 the President was visiting the poor communities in the northeast, “to take a good look at poverty” (Em... 2003); and another one about the Consumer Price Index (CPI) of 2002, in

The overview enabled to conclude that although several tools exist that help players to play by giving statistical information and opponent characteristics there is no

The objective of this study was to develop a method for determining the elastic moduli of coffee stems and branches by comparing the experimentally obtained natural frequency with