# Input: 3n in Output: standart output

Скачати 14.94 Kb.
 Назва Input: 3n in Output: standart output Дата 13.07.2012 Розмір 14.94 Kb. Тип Документи

Problem A: 3n + 1

Input: 3n.in

Output: standart output

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

5. else

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 operations 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 Sample Output 1 10 100 200 201 210 900 1000 1 10 20 100 200 125 201 210 89 900 1000 174

^ Problem B: Zeros and Ones

Input: zo.in

Output: standard output

Time Limit: 2 seconds

Given a string of 0's and 1's up to 1000000 characters long and indices i and j, you are to answer a question whether all characters between position min(i,j) and position max(i,j) (inclusive) are the same.

Input

There are multiple cases on input. The first line of each case gives a string of 0's and 1's. The next line contains a positive integer n giving the number of queries for this case. The next n lines contain queries, one per line. Each query is given by two non-negative integers, i and j. For each query, you are to print Yes if all characters in the string between position min(i,j) and position max(i,j) are the same, and No otherwise.

Output

Each case on output should start with a heading as in the sample below. The input ends with an empty string that is a line containing only the new line character, this string should not be processed. The input may also with end of file. So keep check for both.

^ Sample Input

0000011111

3

0 5

4 2

5 9

01010101010101010101010101111111111111111111111111111111111110000000000000000

5

4 4

25 60

1 3

62 76

24 62

1

1

0 0

^ Sample Output

Case 1:

No

Yes

Yes

Case 2:

Yes

Yes

No

Yes

No

Case 3:

Yes

Problem C : Teobaldo's Trip

Input: trip.in

^ Output: standard output

Time Limit: 1 second

Teobaldo works for the Brazilian government. In his job, he travels a lot. When Teolbaldo travels from a city S to a city E he can spend up to D days in the trip.

As Teobaldo doesn't like to work, he always spend the maximum number of days in his trips. In each day of his trip, Teobaldo sleeps in a different city from the previous day, because he thinks it is boring to stay in the same city two consecutive days.

In this problem, you should help Teobaldo to schedule his trips.

Input

The input file contains several input sets. The description of each set is given below:

Each set starts with two integers C (0 < C ? 100), the number of cities, and L (0 ? L ? 500), the number of links between the cities. Follow L lines, where each line has two numbers: A and B (1 ? A,B ? C), meaning there is a link between these two cities. You can assume that A and B are different numbers. After the L lines, there are three integers: S,E and D. Where S is the city where the trip must start, E is the city where the trip must end, and D (0 ? D ? 200) is the maximum number of days for Teobaldo to go from S to E.

Input is terminated by a set where C=L=0. This set should not be processed. There is a blank line between two input sets.

Output

For each input set produce one line of output, indicating if Teobaldo can travel how he wishes. See the examples below for the exact input/output format.
 Sample Input Sample Output 3 2 1 2 2 3 3 1 23 2 1 2 1 3 1 3 20 0 Yes, Teobaldo can travel. No, Teobaldo can not travel

.

## Схожі:

 Input: 3n in Output: standart output Environmental stochastic input-output model and its deterministic equivalent Texts for tests Hardware. Input/Output hardware Output and Inflation: Are We Mismeasuring Them? The "cpi inflation" and "Chain-Weight gdp" Debates Документи1. /Дерматовенерология/standart dermat.doc Документи1. /Сексопатология/STANDART-Прав.rtf Energy analysis of periodic processes in circuit rl at nonharmonic input voltageАннотация. Дан энергетический анализ периодических процессов в цепи rl с изменяющимися параметрами на основе компонент полной мощности... Документи... Документи1. /приказы/Аллергология/All.krop.1.doc2. /приказы/Аллергология/STAND-2/Angio.nabr..doc Документи1. /Ф_нансове право Украхни - Косаняк/Автореферати/239.doc2. /Ф_нансове...
Додайте кнопку на своєму сайті:
Документи

База даних захищена авторським правом ©zavantag.com 2000-2013
При копіюванні матеріалу обов'язкове зазначення активного посилання відкритою для індексації.
звернутися до адміністрації