Upload 49 files
Browse files- 100.md +59 -0
- 10008.md +42 -0
- 10019.md +37 -0
- 10035.md +25 -0
- 10038.md +22 -0
- 10041.md +26 -0
- 10050.md +94 -0
- 10055.md +25 -0
- 10056.md +38 -0
- 10057.md +43 -0
- 10062.md +27 -0
- 10071.md +20 -0
- 10093.md +29 -0
- 10101.md +22 -0
- 10170.md +36 -0
- 10189.md +60 -0
- 10190.md +37 -0
- 10193.md +62 -0
- 10221.md +33 -0
- 10222.md +27 -0
- 10226.md +90 -0
- 10235.md +35 -0
- 10242.md +25 -0
- 10252.md +28 -0
- 10268.md +34 -0
- 10409.md +56 -0
- 10415.md +55 -0
- 10420.md +33 -0
- 10642.md +36 -0
- 10783.md +25 -0
- 10812.md +28 -0
- 10908.md +52 -0
- 10922.md +26 -0
- 10929.md +27 -0
- 10931.md +27 -0
- 11005.md +73 -0
- 11063.md +25 -0
- 11150.md +33 -0
- 11321.md +64 -0
- 11332.md +35 -0
- 11349.md +62 -0
- 11417.md +43 -0
- 11461.md +22 -0
- 118.md +62 -0
- 12019.md +50 -0
- 272.md +50 -0
- 299.md +42 -0
- 490.md +46 -0
- 948.md +104 -0
100.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
100
|
| 6 |
+
The 3n + 1 problem
|
| 7 |
+
Problems in Computer Science are often classified as belonging to a certain class of problems (e.g.,
|
| 8 |
+
NP, Unsolvable, Recursive). In this problem you will be analyzing a property of an algorithm whose
|
| 9 |
+
classification is not known for all possible inputs.
|
| 10 |
+
Consider the following algorithm:
|
| 11 |
+
1.
|
| 12 |
+
input n
|
| 13 |
+
2.
|
| 14 |
+
print n
|
| 15 |
+
3.
|
| 16 |
+
if n = 1 then STOP
|
| 17 |
+
4.
|
| 18 |
+
if n is odd then n ←−3n + 1
|
| 19 |
+
5.
|
| 20 |
+
else n ←−n/2
|
| 21 |
+
6.
|
| 22 |
+
GOTO 2
|
| 23 |
+
Given the input 22, the following sequence of numbers will be printed
|
| 24 |
+
22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
|
| 25 |
+
It is conjectured that the algorithm above will terminate (when a 1 is printed) for any integral input
|
| 26 |
+
value. Despite the simplicity of the algorithm, it is unknown whether this conjecture is true. It has
|
| 27 |
+
been verified, however, for all integers n such that 0 < n < 1, 000, 000 (and, in fact, for many more
|
| 28 |
+
numbers than this.)
|
| 29 |
+
Given an input n, it is possible to determine the number of numbers printed before and including
|
| 30 |
+
the 1 is printed. For a given n this is called the cycle-length of n. In the example above, the cycle
|
| 31 |
+
length of 22 is 16.
|
| 32 |
+
For any two numbers i and j you are to determine the maximum cycle length over all numbers
|
| 33 |
+
between and including both i and j.
|
| 34 |
+
Input
|
| 35 |
+
The input will consist of a series of pairs of integers i and j, one pair of integers per line. All integers
|
| 36 |
+
will be less than 10,000 and greater than 0.
|
| 37 |
+
You should process all pairs of integers and for each pair determine the maximum cycle length over
|
| 38 |
+
all integers between and including i and j.
|
| 39 |
+
You can assume that no operation overflows a 32-bit integer.
|
| 40 |
+
Output
|
| 41 |
+
For each pair of input integers i and j you should output i, j, and the maximum cycle length for integers
|
| 42 |
+
between and including i and j. These three numbers should be separated by at least one space with all
|
| 43 |
+
three numbers on one line and with one line of output for each line of input. The integers i and j must
|
| 44 |
+
appear in the output in the same order in which they appeared in the input and should be followed by
|
| 45 |
+
the maximum cycle length (on the same line).
|
| 46 |
+
Sample Input
|
| 47 |
+
1 10
|
| 48 |
+
100 200
|
| 49 |
+
201 210
|
| 50 |
+
900 1000
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
## Page 2
|
| 54 |
+
|
| 55 |
+
Sample Output
|
| 56 |
+
1 10 20
|
| 57 |
+
100 200 125
|
| 58 |
+
201 210 89
|
| 59 |
+
900 1000 174
|
10008.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10008
|
| 6 |
+
What’s Cryptanalysis?
|
| 7 |
+
Cryptanalysis is the process of breaking someone else’s cryptographic writing. This sometimes involves
|
| 8 |
+
some kind of statistical analysis of a passage of (encrypted) text. Your task is to write a program which
|
| 9 |
+
performs a simple analysis of a given text.
|
| 10 |
+
Input
|
| 11 |
+
The first line of input contains a single positive decimal integer n. This is the number of lines which
|
| 12 |
+
follow in the input. The next n lines will contain zero or more characters (possibly including whitespace).
|
| 13 |
+
This is the text which must be analyzed.
|
| 14 |
+
Output
|
| 15 |
+
Each line of output contains a single uppercase letter, followed by a single space, then followed by a
|
| 16 |
+
positive decimal integer. The integer indicates how many times the corresponding letter appears in the
|
| 17 |
+
input text. Upper and lower case letters in the input are to be considered the same. No other characters
|
| 18 |
+
must be counted. The output must be sorted in descending count order; that is, the most frequent
|
| 19 |
+
letter is on the first output line, and the last line of output indicates the least frequent letter. If two
|
| 20 |
+
letters have the same frequency, then the letter which comes first in the alphabet must appear first in
|
| 21 |
+
the output. If a letter does not appear in the text, then that letter must not appear in the output.
|
| 22 |
+
Sample Input
|
| 23 |
+
3
|
| 24 |
+
This is a test.
|
| 25 |
+
Count me 1 2 3 4 5.
|
| 26 |
+
Wow!!!!
|
| 27 |
+
Is this question easy?
|
| 28 |
+
Sample Output
|
| 29 |
+
S 7
|
| 30 |
+
T 6
|
| 31 |
+
I 5
|
| 32 |
+
E 4
|
| 33 |
+
O 3
|
| 34 |
+
A 2
|
| 35 |
+
H 2
|
| 36 |
+
N 2
|
| 37 |
+
U 2
|
| 38 |
+
W 2
|
| 39 |
+
C 1
|
| 40 |
+
M 1
|
| 41 |
+
Q 1
|
| 42 |
+
Y 1
|
10019.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10019
|
| 6 |
+
Funny Encryption Method
|
| 7 |
+
A student from ITESM Campus Monterrey plays with a new encryption method for numbers. These
|
| 8 |
+
method consist of the following steps:
|
| 9 |
+
Steps : Example
|
| 10 |
+
1. Read the number N to encrypt : M = 265
|
| 11 |
+
2. Interpret N as a decimal number : X1 = 265 (decimal)
|
| 12 |
+
3. Convert the decimal interpretation of N to its binary representation : X1 = 100001001 (binary)
|
| 13 |
+
4. Let b1 be equal to the number of 1’s in this binary representation : b1 = 3
|
| 14 |
+
5. Interpret N as a Hexadecimal number : X2 = 265 (hexadecimal)
|
| 15 |
+
6. Convert the hexadecimal interpretation of N to its binary representation : X2 = 1001100101
|
| 16 |
+
7. Let b2 be equal to the number of 1’s in the last binary representation : b2 = 5
|
| 17 |
+
8. The encryption is the result of M xor (b1 ∗b2) : 265 xor (3*5) = 262
|
| 18 |
+
This student failed Computational Organization, thats why this student asked the judges of ITESM
|
| 19 |
+
Campus Monterrey internal ACM programming Contest to ask for the numbers of 1’s bits of this two
|
| 20 |
+
representations so that he can continue playing.
|
| 21 |
+
You have to write a program that read a Number and give as output the number b1 and b2
|
| 22 |
+
Input
|
| 23 |
+
The first line will contain a number N which is the number of cases that you have to process. Each
|
| 24 |
+
of the following N Lines (0 < N ≤1000) will contain the number M (0 < M ≤9999, in decimal
|
| 25 |
+
representation) which is the number the student wants to encrypt.
|
| 26 |
+
Output
|
| 27 |
+
You will have to output N lines, each containing the number b1 and b2 in that order, separated by one
|
| 28 |
+
space corresponding to that lines number to crypt
|
| 29 |
+
Sample Input
|
| 30 |
+
3
|
| 31 |
+
265
|
| 32 |
+
111
|
| 33 |
+
1234
|
| 34 |
+
Sample Output
|
| 35 |
+
3 5
|
| 36 |
+
6 3
|
| 37 |
+
5 5
|
10035.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10035
|
| 6 |
+
Primary Arithmetic
|
| 7 |
+
Children are taught to add multi-digit numbers from right-to-left one digit at a time. Many find the
|
| 8 |
+
“carry” operation - in which a 1 is carried from one digit position to be added to the next - to be a
|
| 9 |
+
significant challenge. Your job is to count the number of carry operations for each of a set of addition
|
| 10 |
+
problems so that educators may assess their difficulty.
|
| 11 |
+
Input
|
| 12 |
+
Each line of input contains two unsigned integers less than 10 digits. The last line of input contains ‘0
|
| 13 |
+
0’.
|
| 14 |
+
Output
|
| 15 |
+
For each line of input except the last you should compute and print the number of carry operations
|
| 16 |
+
that would result from adding the two numbers, in the format shown below.
|
| 17 |
+
Sample Input
|
| 18 |
+
123 456
|
| 19 |
+
555 555
|
| 20 |
+
123 594
|
| 21 |
+
0 0
|
| 22 |
+
Sample Output
|
| 23 |
+
No carry operation.
|
| 24 |
+
3 carry operations.
|
| 25 |
+
1 carry operation.
|
10038.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10038
|
| 6 |
+
Jolly Jumpers
|
| 7 |
+
A sequence of n > 0 integers is called a jolly jumper if the absolute values of the difference between
|
| 8 |
+
successive elements take on all the values 1 through n −1. For instance,
|
| 9 |
+
1 4 2 3
|
| 10 |
+
is a jolly jumper, because the absolutes differences are 3, 2, and 1 respectively. The definition implies
|
| 11 |
+
that any sequence of a single integer is a jolly jumper. You are to write a program to determine whether
|
| 12 |
+
or not each of a number of sequences is a jolly jumper.
|
| 13 |
+
Input
|
| 14 |
+
Each line of input contains an integer n ≤3000 followed by n integers representing the sequence.
|
| 15 |
+
Output
|
| 16 |
+
For each line of input, generate a line of output saying ‘Jolly’ or ‘Not jolly’.
|
| 17 |
+
Sample Input
|
| 18 |
+
4 1 4 2 3
|
| 19 |
+
5 1 4 2 -1 6
|
| 20 |
+
Sample Output
|
| 21 |
+
Jolly
|
| 22 |
+
Not jolly
|
10041.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10041
|
| 6 |
+
Vito’s family
|
| 7 |
+
The world-known gangster Vito Deadstone is moving to New York. He has a very big family there, all
|
| 8 |
+
of them living in Lamafia Avenue. Since he will visit all his relatives very often, he is trying to find a
|
| 9 |
+
house close to them.
|
| 10 |
+
Vito wants to minimize the total distance to all of them and has blackmailed you to write a program
|
| 11 |
+
that solves his problem.
|
| 12 |
+
Input
|
| 13 |
+
The input consists of several test cases. The first line contains the number of test cases.
|
| 14 |
+
For each test case you will be given the integer number of relatives r (0 < r < 500) and the
|
| 15 |
+
street numbers (also integers) s1, s2, . . . , si, . . . , sr where they live (0 < si < 30000 ). Note that several
|
| 16 |
+
relatives could live in the same street number.
|
| 17 |
+
Output
|
| 18 |
+
For each test case your program must write the minimal sum of distances from the optimal Vito’s house
|
| 19 |
+
to each one of his relatives. The distance between two street numbers si and sj is dij = |si −sj|.
|
| 20 |
+
Sample Input
|
| 21 |
+
2
|
| 22 |
+
2 2 4
|
| 23 |
+
3 2 4 6
|
| 24 |
+
Sample Output
|
| 25 |
+
2
|
| 26 |
+
4
|
10050.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10050
|
| 6 |
+
Hartals
|
| 7 |
+
A social research organization has determined a simple set of parameters to simulate the behavior of
|
| 8 |
+
the political parties of our country. One of the parameters is a positive integer h (called the hartal
|
| 9 |
+
parameter) that denotes the average number of days between two successive hartals (strikes) called by
|
| 10 |
+
the corresponding party. Though the parameter is far too simple to be flawless, it can still be used to
|
| 11 |
+
forecast the damages caused by hartals. The following example will give you a clear idea:
|
| 12 |
+
Consider three political parties. Assume h1 = 3, h2 = 4 and h3 = 8 where hi is the hartal parameter
|
| 13 |
+
for party i (i = 1, 2, 3). Now, we will simulate the behavior of these three parties for N = 14 days.
|
| 14 |
+
One must always start the simulation on a Sunday and assume that there will be no hartals on weekly
|
| 15 |
+
holidays (on Fridays and Saturdays).
|
| 16 |
+
1
|
| 17 |
+
2
|
| 18 |
+
3
|
| 19 |
+
4
|
| 20 |
+
5
|
| 21 |
+
6
|
| 22 |
+
7
|
| 23 |
+
8
|
| 24 |
+
9
|
| 25 |
+
10
|
| 26 |
+
11
|
| 27 |
+
12
|
| 28 |
+
13
|
| 29 |
+
14
|
| 30 |
+
Days
|
| 31 |
+
Su
|
| 32 |
+
Mo
|
| 33 |
+
Tu
|
| 34 |
+
We
|
| 35 |
+
Th
|
| 36 |
+
Fr
|
| 37 |
+
Sa
|
| 38 |
+
Su
|
| 39 |
+
Mo
|
| 40 |
+
Tu
|
| 41 |
+
We
|
| 42 |
+
Th
|
| 43 |
+
Fr
|
| 44 |
+
Sa
|
| 45 |
+
Party 1
|
| 46 |
+
x
|
| 47 |
+
x
|
| 48 |
+
x
|
| 49 |
+
x
|
| 50 |
+
Party 2
|
| 51 |
+
x
|
| 52 |
+
x
|
| 53 |
+
x
|
| 54 |
+
Party 3
|
| 55 |
+
x
|
| 56 |
+
Hartals
|
| 57 |
+
1
|
| 58 |
+
2
|
| 59 |
+
3
|
| 60 |
+
4
|
| 61 |
+
5
|
| 62 |
+
The simulation above shows that there will be exactly 5 hartals (on days 3, 4, 8, 9 and 12) in 14
|
| 63 |
+
days. There will be no hartal on day 6 since it is a Friday. Hence we lose 5 working days in 2 weeks.
|
| 64 |
+
In this problem, given the hartal parameters for several political parties and the value of N, your
|
| 65 |
+
job is to determine the number of working days we lose in those N days.
|
| 66 |
+
Input
|
| 67 |
+
The first line of the input consists of a single integer T giving the number of test cases to follow.
|
| 68 |
+
The first line of each test case contains an integer N (7 ≤N ≤3650) giving the number of days over
|
| 69 |
+
which the simulation must be run. The next line contains another integer P (1 ≤P ≤100) representing
|
| 70 |
+
the number of political parties in this case. The i th of the next P lines contains a positive integer hi
|
| 71 |
+
(which will never be a multiple of 7) giving the hartal parameter for party i (1 ≤i ≤P).
|
| 72 |
+
Output
|
| 73 |
+
For each test case in the input output the number of working days we lose. Each output must be on a
|
| 74 |
+
separate line.
|
| 75 |
+
Sample Input
|
| 76 |
+
2
|
| 77 |
+
14
|
| 78 |
+
3
|
| 79 |
+
3
|
| 80 |
+
4
|
| 81 |
+
8
|
| 82 |
+
100
|
| 83 |
+
4
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
## Page 2
|
| 87 |
+
|
| 88 |
+
12
|
| 89 |
+
15
|
| 90 |
+
25
|
| 91 |
+
40
|
| 92 |
+
Sample Output
|
| 93 |
+
5
|
| 94 |
+
15
|
10055.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10055
|
| 6 |
+
Hashmat the brave warrior
|
| 7 |
+
Hashmat is a brave warrior who with his group of young soldiers moves from one place to another to
|
| 8 |
+
fight against his opponents. Before Fighting he just calculates one thing, the difference between his
|
| 9 |
+
soldier number and the opponent’s soldier number. From this difference he decides whether to fight or
|
| 10 |
+
not. Hashmat’s soldier number is never greater than his opponent.
|
| 11 |
+
Input
|
| 12 |
+
The input contains two numbers in every line. These two numbers in each line denotes the number
|
| 13 |
+
soldiers in Hashmat’s army and his opponent’s army or vice versa. The input numbers are not greater
|
| 14 |
+
than 232. Input is terminated by ‘End of File’.
|
| 15 |
+
Output
|
| 16 |
+
For each line of input, print the difference of number of soldiers between Hashmat’s army and his
|
| 17 |
+
opponent’s army. Each output should be in seperate line.
|
| 18 |
+
Sample Input
|
| 19 |
+
10 12
|
| 20 |
+
10 14
|
| 21 |
+
100 200
|
| 22 |
+
Sample Output
|
| 23 |
+
2
|
| 24 |
+
4
|
| 25 |
+
100
|
10056.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10056
|
| 6 |
+
What is the Probability?
|
| 7 |
+
Probability has always been an integrated part of computer algorithms.
|
| 8 |
+
Where the deterministic
|
| 9 |
+
algorithms have failed to solve a problem in short time, probabilistic algorithms have come to the
|
| 10 |
+
rescue.
|
| 11 |
+
In this problem we are not dealing with any probabilistic algorithm.
|
| 12 |
+
We will just try to
|
| 13 |
+
determine the winning probability of a certain player.
|
| 14 |
+
A game is played by throwing a dice like thing (it should not be assumed that it has six sides like
|
| 15 |
+
an ordinary dice). If a certain event occurs when a player throws the dice (such as getting a 3, getting
|
| 16 |
+
green side on top or whatever) he is declared the winner. There can be N such player. So the first
|
| 17 |
+
player will throw the dice, then the second and at last the N-th player and again the first player and
|
| 18 |
+
so on. When a player gets the desired event he or she is declared winner and playing stops. You will
|
| 19 |
+
have to determine the winning probability of one (The I-th) of these players.
|
| 20 |
+
Input
|
| 21 |
+
Input will contain an integer S (S ≤1000) at first, which indicates how many sets of inputs are there.
|
| 22 |
+
The next S lines will contain S sets of inputs. Each line contain an integer N (N ≤1000) which denotes
|
| 23 |
+
the number players, a floating point number p which indicates the probability of the happening of a
|
| 24 |
+
successful event in a single throw (If success means getting 3 then p is the probability of getting 3 in
|
| 25 |
+
a single throw. For a normal dice the probability of getting 3 is 1/6), and I (I ≤N) the serial of the
|
| 26 |
+
player whose winning probability is to be determined (Serial no varies from 1 to N). You can assume
|
| 27 |
+
that no invalid probability (p) value will be given as input.
|
| 28 |
+
Output
|
| 29 |
+
For each set of input, output in a single line the probability of the I-th player to win. The output
|
| 30 |
+
floating point number will always have four digits after the decimal point as shown in the sample
|
| 31 |
+
output.
|
| 32 |
+
Sample Input
|
| 33 |
+
2
|
| 34 |
+
2 0.166666 1
|
| 35 |
+
2 0.166666 2
|
| 36 |
+
Sample Output
|
| 37 |
+
0.5455
|
| 38 |
+
0.4545
|
10057.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10057
|
| 6 |
+
A mid-summer night’s dream
|
| 7 |
+
This is year 2200AD. Science has progressed a lot in two hundred years. Two hundred years is mentioned
|
| 8 |
+
here because this problem is being sent back to 2000AD with the help of time machine. Now it is possible
|
| 9 |
+
to establish direct connection between man and computer CPU. People can watch other peoples dream
|
| 10 |
+
on 3D displayer (That is the monitor today) as if they were watching a movie.
|
| 11 |
+
One problem in
|
| 12 |
+
this century is that people have become so dependent on computers that their analytical ability is
|
| 13 |
+
approaching zero. Computers can now read problems and solve them automatically. But they can solve
|
| 14 |
+
only difficult problems. There are no easy problems now. Our chief scientist is in great trouble as he
|
| 15 |
+
has forgotten the number of his combination lock. For security reasons computers today cannot solve
|
| 16 |
+
combination lock related problems. In a mid-summer night the scientist has a dream where he sees a
|
| 17 |
+
lot of unsigned integer numbers flying around. He records them with the help of his computer, Then
|
| 18 |
+
he has a clue that if the numbers are (X1, X2, …, Xn) he will have to find an integer number A (This
|
| 19 |
+
A is the combination lock code) such that
|
| 20 |
+
(|X1 −A| + |X2 −A| + . . . + |Xn −A|)
|
| 21 |
+
is minimum.
|
| 22 |
+
Input
|
| 23 |
+
Input will contain several blocks. Each block will start with a number n (0 < n ≤1000000) indicating
|
| 24 |
+
how many numbers he saw in the dream. Next there will be n numbers. All the numbers will be less
|
| 25 |
+
that 65536. The input will be terminated by end of file.
|
| 26 |
+
Output
|
| 27 |
+
For each set of input there will be one line of output. That line will contain the minimum possible
|
| 28 |
+
value for A. Next it will contain how many numbers are there in the input that satisfy the property
|
| 29 |
+
of A (The summation of absolute deviation from A is minimum). And finally you have to print how
|
| 30 |
+
many possible different integer values are there for A (these values need not be present in the input).
|
| 31 |
+
These numbers will be separated by single space.
|
| 32 |
+
Sample Input
|
| 33 |
+
2
|
| 34 |
+
10
|
| 35 |
+
10
|
| 36 |
+
4
|
| 37 |
+
1
|
| 38 |
+
2
|
| 39 |
+
2
|
| 40 |
+
4
|
| 41 |
+
Sample Output
|
| 42 |
+
10 2 1
|
| 43 |
+
2 2 1
|
10062.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10062
|
| 6 |
+
Tell me the frequencies!
|
| 7 |
+
Given a line of text you will have to find out the frequencies of the ASCII characters present in it. The
|
| 8 |
+
given lines will contain none of the first 32 or last 128 ASCII characters. Of course lines may end with
|
| 9 |
+
\n and \r but always keep those out of consideration.
|
| 10 |
+
Input
|
| 11 |
+
Several lines of text are given as input. Each line of text is considered as a single input. Maximum
|
| 12 |
+
length of each line is 1000.
|
| 13 |
+
Output
|
| 14 |
+
Print the ASCII value of the ASCII characters which are present and their frequency according to the
|
| 15 |
+
given format below. A blank line should separate each set of output. Print the ASCII characters in the
|
| 16 |
+
ascending order of their frequencies. If two characters are present the same time print the information
|
| 17 |
+
of the ASCII character with higher ASCII value first. Input is terminated by end of file.
|
| 18 |
+
Sample Input
|
| 19 |
+
AAABBC
|
| 20 |
+
122333
|
| 21 |
+
Sample Output
|
| 22 |
+
67 1
|
| 23 |
+
66 2
|
| 24 |
+
65 3
|
| 25 |
+
49 1
|
| 26 |
+
50 2
|
| 27 |
+
51 3
|
10071.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10071
|
| 6 |
+
Back to High School Physics
|
| 7 |
+
A particle has initial velocity and acceleration. If its velocity after certain time is v then what will its
|
| 8 |
+
displacement be in twice of that time?
|
| 9 |
+
Input
|
| 10 |
+
The input will contain two integers in each line. Each line makes one set of input. These two integers
|
| 11 |
+
denote the value of v (−100 ≤v ≤100) and t (0 ≤t ≤200) (t means at the time the particle gains
|
| 12 |
+
that velocity)
|
| 13 |
+
Output
|
| 14 |
+
For each line of input print a single integer in one line denoting the displacement in double of that time.
|
| 15 |
+
Sample Input
|
| 16 |
+
0 0
|
| 17 |
+
5 12
|
| 18 |
+
Sample Output
|
| 19 |
+
0
|
| 20 |
+
120
|
10093.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10093
|
| 6 |
+
An Easy Problem!
|
| 7 |
+
Have you heard the fact “The base of every normal number system is 10”? Of course, I am not talking
|
| 8 |
+
about number systems like Stern Brockot Number System. This problem has nothing to do with this
|
| 9 |
+
fact but may have some similarity.
|
| 10 |
+
You will be given an N based integer number R and you are given the guaranty that R is divisible
|
| 11 |
+
by (N −1). You will have to print the smallest possible value for N. The range for N is 2 ≤N ≤62
|
| 12 |
+
and the digit symbols for 62 based number is (0..9 and A..Z and a..z). Similarly, the digit symbols
|
| 13 |
+
for 61 based number system is 0..9 and A..Z and a..y) and so on.
|
| 14 |
+
Input
|
| 15 |
+
Each line in the input file will contain an integer (as defined in mathematics) number of any integer
|
| 16 |
+
base (2..62). You will have to determine what is the smallest possible base of that number for the given
|
| 17 |
+
conditions. No invalid number will be given as input.
|
| 18 |
+
Output
|
| 19 |
+
If number with such condition is not possible output the line ‘such number is impossible!’ For each
|
| 20 |
+
line of input there will be only a single line of output. The output will always be in decimal number
|
| 21 |
+
system.
|
| 22 |
+
Sample Input
|
| 23 |
+
3
|
| 24 |
+
5
|
| 25 |
+
A
|
| 26 |
+
Sample Output
|
| 27 |
+
4
|
| 28 |
+
6
|
| 29 |
+
11
|
10101.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10101
|
| 6 |
+
Bangla Numbers
|
| 7 |
+
Bangla numbers normally use ’kuti’ (10000000), ’lakh’ (100000), ’hajar’ (1000), ’shata’ (100) while
|
| 8 |
+
expanding and converting to text. You are going to write a program to convert a given number to text
|
| 9 |
+
with them.
|
| 10 |
+
Input
|
| 11 |
+
The input file may contain several test cases.
|
| 12 |
+
Each case will contain a non-negative number
|
| 13 |
+
≤999999999999999.
|
| 14 |
+
Output
|
| 15 |
+
For each case of input, you have to output a line starting with the case number with four digits
|
| 16 |
+
adjustment followed by the converted text.
|
| 17 |
+
Sample Input
|
| 18 |
+
23764
|
| 19 |
+
45897458973958
|
| 20 |
+
Sample Output
|
| 21 |
+
1. 23 hajar 7 shata 64
|
| 22 |
+
2. 45 lakh 89 hajar 7 shata 45 kuti 89 lakh 73 hajar 9 shata 58
|
10170.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10170
|
| 6 |
+
The Hotel with Infinite Rooms
|
| 7 |
+
The city of HaluaRuti has a strange hotel with infinite rooms. The groups that come to this hotel
|
| 8 |
+
follow the following rules:
|
| 9 |
+
a) At the same time only members of one group can rent the hotel.
|
| 10 |
+
b) Each group comes in the morning of the check-in day and leaves the hotel in the evening of the
|
| 11 |
+
check-out day.
|
| 12 |
+
c) Another group comes in the very next morning after the previous group has left the hotel.
|
| 13 |
+
d) A very important property of the incoming group is that it has one more member than its previous
|
| 14 |
+
group unless it is the starting group. You will be given the no of members of the starting group.
|
| 15 |
+
e) A group with n members stays for n days in the hotel. For example, if a group of four members
|
| 16 |
+
comes on 1st August in the morning, it will leave the hotel on 4th August in the evening and the
|
| 17 |
+
next group of five members will come on 5th August in the morning and stay for five days and so
|
| 18 |
+
on.
|
| 19 |
+
Given the initial group size you will have to find the group size staying in the hotel on a specified
|
| 20 |
+
day.
|
| 21 |
+
Input
|
| 22 |
+
The input contains round numbers S (1 ≤S ≤10000) and D (1 ≤D < 1015) in every line. S denotes
|
| 23 |
+
the initial size of the group and D denotes that you will have to find the group size staying in the hotel
|
| 24 |
+
on D-th day (starting from 1). All the input and output integers will be less than 1015. A group size S
|
| 25 |
+
means that on the first day a group of S members come to the hotel and stays for S days then comes
|
| 26 |
+
a group of S + 1 members according to the previously described rules and so on.
|
| 27 |
+
Output
|
| 28 |
+
For each line of input, print on a single line the size of the group staying in the hotel on the D-th day.
|
| 29 |
+
Sample Input
|
| 30 |
+
1 6
|
| 31 |
+
3 10
|
| 32 |
+
3 14
|
| 33 |
+
Sample Output
|
| 34 |
+
3
|
| 35 |
+
5
|
| 36 |
+
6
|
10189.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10189
|
| 6 |
+
Minesweeper
|
| 7 |
+
Have you ever played Minesweeper? It’s a cute little game which comes within a certain Operating
|
| 8 |
+
System which name we can’t really remember. Well, the goal of the game is to find where are all the
|
| 9 |
+
mines within a M × N field. To help you, the game shows a number in a square which tells you how
|
| 10 |
+
many mines there are adjacent to that square. For instance, supose the following 4 × 4 field with 2
|
| 11 |
+
mines (which are represented by an ‘*’ character):
|
| 12 |
+
*...
|
| 13 |
+
....
|
| 14 |
+
.*..
|
| 15 |
+
....
|
| 16 |
+
If we would represent the same field placing the hint numbers described above, we would end up
|
| 17 |
+
with:
|
| 18 |
+
*100
|
| 19 |
+
2210
|
| 20 |
+
1*10
|
| 21 |
+
1110
|
| 22 |
+
As you may have already noticed, each square may have at most 8 adjacent squares.
|
| 23 |
+
Input
|
| 24 |
+
The input will consist of an arbitrary number of fields. The first line of each field contains two integers
|
| 25 |
+
n and m (0 < n, m ≤100) which stands for the number of lines and columns of the field respectively.
|
| 26 |
+
The next n lines contains exactly m characters and represent the field.
|
| 27 |
+
Each safe square is represented by an ‘.’ character (without the quotes) and each mine square
|
| 28 |
+
is represented by an ‘*’ character (also without the quotes). The first field line where n = m = 0
|
| 29 |
+
represents the end of input and should not be processed.
|
| 30 |
+
Output
|
| 31 |
+
For each field, you must print the following message in a line alone:
|
| 32 |
+
Field #x:
|
| 33 |
+
Where x stands for the number of the field (starting from 1). The next n lines should contain the
|
| 34 |
+
field with the ‘.’ characters replaced by the number of adjacent mines to that square. There must be
|
| 35 |
+
an empty line between field outputs.
|
| 36 |
+
Sample Input
|
| 37 |
+
4 4
|
| 38 |
+
*...
|
| 39 |
+
....
|
| 40 |
+
.*..
|
| 41 |
+
....
|
| 42 |
+
3 5
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
## Page 2
|
| 46 |
+
|
| 47 |
+
**...
|
| 48 |
+
.....
|
| 49 |
+
.*...
|
| 50 |
+
0 0
|
| 51 |
+
Sample Output
|
| 52 |
+
Field #1:
|
| 53 |
+
*100
|
| 54 |
+
2210
|
| 55 |
+
1*10
|
| 56 |
+
1110
|
| 57 |
+
Field #2:
|
| 58 |
+
**100
|
| 59 |
+
33200
|
| 60 |
+
1*100
|
10190.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10190
|
| 6 |
+
Divide, But Not Quite Conquer!
|
| 7 |
+
Your goal in this problem is to divide a certain integer n by another integer m until n = 1, obtaining
|
| 8 |
+
a sequence of numbers. Lets call a[i] each number of this sequence, and let’s say it has k numbers (i.e.
|
| 9 |
+
you must do k −1 succesive divisions to reach n = 1). You can only have this sequence if the following
|
| 10 |
+
restrictions are met:
|
| 11 |
+
• a[1] = n, a[i] = a[i −1] ÷ m, for all 1 < i ≤k
|
| 12 |
+
• a[i] is divisible by m (that is, a[i] mod m = 0) for all 1 ≤i < k
|
| 13 |
+
• a[1] > a[2] > a[3] > . . . > a[k]
|
| 14 |
+
For instance, if n = 125 and m = 5, you have 125, 25, 5 and 1 (you did 3 divisions: 125/5, 25/5 and
|
| 15 |
+
5/5). So, k = 4, a[1] = 125, a[2] = 25, a[3] = 5 and a[4] = 1.
|
| 16 |
+
If n = 30 and m = 3, you have 30, 10, 3 and 1. But a[2] = 10, and 10 mod 3 = 1, so there is no
|
| 17 |
+
sequence because it violates restriction 2. When the sequence doesn’t exist we think it’s not fun and,
|
| 18 |
+
thus, very boring!
|
| 19 |
+
Input
|
| 20 |
+
The input will consist on an arbitrary number of lines.
|
| 21 |
+
Each line will consist of two non-negative
|
| 22 |
+
integers n, m which are both less than 2000000000. You must read until you reach the end of file.
|
| 23 |
+
Output
|
| 24 |
+
For each pair n, m you must print the correspondent sequence a (as defined above) in a single line, with
|
| 25 |
+
each adjacent numbers of the sequence separated by a single space. In the case the sequence doesn’t
|
| 26 |
+
exist because it violates some restriction, just print the phrase ‘Boring!’ in a single line (without the
|
| 27 |
+
quotes).
|
| 28 |
+
Sample Input
|
| 29 |
+
125 5
|
| 30 |
+
30 3
|
| 31 |
+
80 2
|
| 32 |
+
81 3
|
| 33 |
+
Sample Output
|
| 34 |
+
125 25 5 1
|
| 35 |
+
Boring!
|
| 36 |
+
Boring!
|
| 37 |
+
81 27 9 3 1
|
10193.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10193
|
| 6 |
+
All You Need Is Love
|
| 7 |
+
”All you need is love. All you need is love.
|
| 8 |
+
All you need is love, love... love is all you need.”
|
| 9 |
+
The Beatles
|
| 10 |
+
There was invented a new powerfull gadget by the International Beautifull Machines corporation
|
| 11 |
+
called the love machine! Given a string made of binary digits, the love machine answers if it’s made
|
| 12 |
+
only of love, that is, if all you need is love to build that string. The definition of love for the love
|
| 13 |
+
machine is another string of binary digits, given by a human operator. Let’s say we have a string L
|
| 14 |
+
which represents “love” and we give a string S for the love machine. We say that all you need is love
|
| 15 |
+
to build S, if we can repeatly subtract L from S until we reach L. The subtraction defined here is the
|
| 16 |
+
same arithmetic subtraction in base 2. By this definition it’s easy to see that if L > S (in binary), then
|
| 17 |
+
S is not made of love.
|
| 18 |
+
If S = L then S is obvious made of love.
|
| 19 |
+
Let’s see an example. Supose S = “11011” and L = “11”. If we reapetly subtract L from S, we
|
| 20 |
+
get: 11011, 11000, 10101, 10010, 1111, 1100, 1001, 110, 11. So, given this L, all you need is love to
|
| 21 |
+
build S. Because of some limitations of the love machine, there can be no string with leading zeroes.
|
| 22 |
+
That is, “0010101”, “01110101”, “011111”, etc. are invalid strings. Strings which have only one digit
|
| 23 |
+
are also invalid (it’s another limitation).
|
| 24 |
+
Your task in this problem is: given two valid binary strings, S1 and S2, find if it’s possible to have a
|
| 25 |
+
valid string L such that both S1 and S2 can be made only of L (i.e. given two valid strings S1 and S2,
|
| 26 |
+
find if there exists at least one valid string L such as both S1 and S2 are made only of L). For instance,
|
| 27 |
+
for S1 = 11011 and S2 = 11000, we can have L = 11 such that S1 and S2 are both made only of L (as
|
| 28 |
+
we can see in the example above).
|
| 29 |
+
Input
|
| 30 |
+
The first line of input is a positive integer N < 10000 which stands for the number of teste cases. Then,
|
| 31 |
+
2 ∗N lines will follow. Each pair of lines consists in one teste case. Each line of the pair stands for each
|
| 32 |
+
string (S1 and S2) to be entered as an input for the love machine. No string will have more than 30
|
| 33 |
+
characters. You can assume that all strings in the input will be valid acording to the rules above.
|
| 34 |
+
Output
|
| 35 |
+
For each string pair, you must print one of the following messages:
|
| 36 |
+
Pair #p: All you need is love!
|
| 37 |
+
Pair #p: Love is not all you need!
|
| 38 |
+
Where p stands for the pair number (starting from 1). You should print the first message if there
|
| 39 |
+
exists at least one valid string L such as both S1 and S2 can be made only of L. Otherwise, print the
|
| 40 |
+
second line.
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
## Page 2
|
| 44 |
+
|
| 45 |
+
Sample Input
|
| 46 |
+
5
|
| 47 |
+
11011
|
| 48 |
+
11000
|
| 49 |
+
11011
|
| 50 |
+
11001
|
| 51 |
+
111111
|
| 52 |
+
100
|
| 53 |
+
1000000000
|
| 54 |
+
110
|
| 55 |
+
1010
|
| 56 |
+
100
|
| 57 |
+
Sample Output
|
| 58 |
+
Pair #1: All you need is love!
|
| 59 |
+
Pair #2: Love is not all you need!
|
| 60 |
+
Pair #3: Love is not all you need!
|
| 61 |
+
Pair #4: All you need is love!
|
| 62 |
+
Pair #5: All you need is love!
|
10221.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10221
|
| 6 |
+
Satellites
|
| 7 |
+
The radius of earth is 6440 Kilometer. There are many Satellites
|
| 8 |
+
and Asteroids moving around the earth. If two Satellites create
|
| 9 |
+
an angle with the center of earth, can you find out the distance
|
| 10 |
+
between them?
|
| 11 |
+
By distance we mean both the arc and chord
|
| 12 |
+
distances. Both satellites are on the same orbit (However, please
|
| 13 |
+
consider that they are revolving on a circular path rather than
|
| 14 |
+
an elliptical path).
|
| 15 |
+
Input
|
| 16 |
+
The input file will contain one or more test cases.
|
| 17 |
+
Each test case consists of one line containing two-integer s
|
| 18 |
+
and a, and a string ‘min’ or ‘deg’. Here s is the distance of the
|
| 19 |
+
satellite from the surface of the earth and a is the angle that the
|
| 20 |
+
satellites make with the center of earth. It may be in minutes (′) or in degrees (◦). Remember that the
|
| 21 |
+
same line will never contain minute and degree at a time.
|
| 22 |
+
Output
|
| 23 |
+
For each test case, print one line containing the required distances i.e. both arc distance and chord
|
| 24 |
+
distance respectively between two satellites in Kilometer. The distance will be a floating-point value
|
| 25 |
+
with six digits after decimal point.
|
| 26 |
+
Sample Input
|
| 27 |
+
500 30 deg
|
| 28 |
+
700 60 min
|
| 29 |
+
200 45 deg
|
| 30 |
+
Sample Output
|
| 31 |
+
3633.775503 3592.408346
|
| 32 |
+
124.616509 124.614927
|
| 33 |
+
5215.043805 5082.035982
|
10222.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10222
|
| 6 |
+
Decode the Mad man
|
| 7 |
+
Once in BUET, an old professor had gone completely mad. He started talking with some peculiar
|
| 8 |
+
words. Nobody could realize his speech and lectures. Finally the BUET authority fall in great trouble.
|
| 9 |
+
There was no way left to keep that man working in university. Suddenly a student (definitely he was
|
| 10 |
+
a registered author at UVA ACM Chapter and hold a good rank on 24 hour-Online Judge) created
|
| 11 |
+
a program that was able to decode that professor’s speech. After his invention, everyone got comfort
|
| 12 |
+
again and that old teacher started his everyday works as before.
|
| 13 |
+
So, if you ever visit BUET and see a teacher talking with a microphone, which is connected to a
|
| 14 |
+
IBM computer equipped with a voice recognition software and students are taking their lecture from
|
| 15 |
+
the computer screen, don’t get thundered! Because now your job is to write the same program which
|
| 16 |
+
can decode that mad teacher’s speech!
|
| 17 |
+
Input
|
| 18 |
+
The input file will contain only one test case i.e. the encoded message.
|
| 19 |
+
The test case consists of one or more words.
|
| 20 |
+
Output
|
| 21 |
+
For the given test case, print a line containing the decoded words. However, it is not so hard task to
|
| 22 |
+
replace each letter or punctuation symbol by the two immediately to its left alphabet on your standard
|
| 23 |
+
keyboard.
|
| 24 |
+
Sample Input
|
| 25 |
+
k[r dyt I[o
|
| 26 |
+
Sample Output
|
| 27 |
+
how are you
|
10226.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10226
|
| 6 |
+
Hardwood Species
|
| 7 |
+
Hardwoods are the botanical group of trees that have broad leaves,
|
| 8 |
+
produce a fruit or nut, and generally go dormant in the winter.
|
| 9 |
+
America’s temperate climates produce forests with hundreds of
|
| 10 |
+
hardwood species —trees that share certain biological characteristics.
|
| 11 |
+
Although oak, maple and cherry all are types of hardwood trees, for
|
| 12 |
+
example, they are different species. Together, all the hardwood species
|
| 13 |
+
represent 40 percent of the trees in the United States.
|
| 14 |
+
On the other hand, softwoods, or conifers, from the Latin word
|
| 15 |
+
meaning “cone-bearing”, have needles. Widely available US softwoods
|
| 16 |
+
include cedar, fir, hemlock, pine, redwood, spruce and cypress. In a
|
| 17 |
+
home, the softwoods are used primarily as structural lumber such as
|
| 18 |
+
2×4s and 2×6s, with some limited decorative applications.
|
| 19 |
+
Using satellite imaging technology, the Department of Natural Resources has compiled an inventory
|
| 20 |
+
of every tree standing on a particular day. You are to compute the total fraction of the tree population
|
| 21 |
+
represented by each species.
|
| 22 |
+
Input
|
| 23 |
+
The first line is the number of test cases, followed by a blank line.
|
| 24 |
+
Each test case of your program consists of a list of the species of every tree observed by the satellite;
|
| 25 |
+
one tree per line. No species name exceeds 30 characters. There are no more than 10,000 species and
|
| 26 |
+
no more than 1,000,000 trees.
|
| 27 |
+
There is a blank line between each consecutive test cases.
|
| 28 |
+
Output
|
| 29 |
+
For each test case print the name of each species represented in the population, in alphabetical order,
|
| 30 |
+
followed by the percentage of the population it represents, to 4 decimal places.
|
| 31 |
+
Print a blank line between 2 consecutive test cases.
|
| 32 |
+
Sample Input
|
| 33 |
+
1
|
| 34 |
+
Red Alder
|
| 35 |
+
Ash
|
| 36 |
+
Aspen
|
| 37 |
+
Basswood
|
| 38 |
+
Ash
|
| 39 |
+
Beech
|
| 40 |
+
Yellow Birch
|
| 41 |
+
Ash
|
| 42 |
+
Cherry
|
| 43 |
+
Cottonwood
|
| 44 |
+
Ash
|
| 45 |
+
Cypress
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
## Page 2
|
| 49 |
+
|
| 50 |
+
Red Elm
|
| 51 |
+
Gum
|
| 52 |
+
Hackberry
|
| 53 |
+
White Oak
|
| 54 |
+
Hickory
|
| 55 |
+
Pecan
|
| 56 |
+
Hard Maple
|
| 57 |
+
White Oak
|
| 58 |
+
Soft Maple
|
| 59 |
+
Red Oak
|
| 60 |
+
Red Oak
|
| 61 |
+
White Oak
|
| 62 |
+
Poplan
|
| 63 |
+
Sassafras
|
| 64 |
+
Sycamore
|
| 65 |
+
Black Walnut
|
| 66 |
+
Willow
|
| 67 |
+
Sample Output
|
| 68 |
+
Ash 13.7931
|
| 69 |
+
Aspen 3.4483
|
| 70 |
+
Basswood 3.4483
|
| 71 |
+
Beech 3.4483
|
| 72 |
+
Black Walnut 3.4483
|
| 73 |
+
Cherry 3.4483
|
| 74 |
+
Cottonwood 3.4483
|
| 75 |
+
Cypress 3.4483
|
| 76 |
+
Gum 3.4483
|
| 77 |
+
Hackberry 3.4483
|
| 78 |
+
Hard Maple 3.4483
|
| 79 |
+
Hickory 3.4483
|
| 80 |
+
Pecan 3.4483
|
| 81 |
+
Poplan 3.4483
|
| 82 |
+
Red Alder 3.4483
|
| 83 |
+
Red Elm 3.4483
|
| 84 |
+
Red Oak 6.8966
|
| 85 |
+
Sassafras 3.4483
|
| 86 |
+
Soft Maple 3.4483
|
| 87 |
+
Sycamore 3.4483
|
| 88 |
+
White Oak 10.3448
|
| 89 |
+
Willow 3.4483
|
| 90 |
+
Yellow Birch 3.4483
|
10235.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10235
|
| 6 |
+
Simply Emirp
|
| 7 |
+
An integer greater than 1 is called a prime number if its only positive divisors (factors) are 1 and itself.
|
| 8 |
+
Prime numbers have been studied over the years by a lot of mathematicians. Applications of prime
|
| 9 |
+
numbers arise in Cryptography and Coding Theory among others.
|
| 10 |
+
Have you tried reversing a prime? For most primes, you get a composite (43 becomes 34). An
|
| 11 |
+
Emirp (Prime spelt backwards) is a Prime that gives you a different Prime when its digits are reversed.
|
| 12 |
+
For example, 17 is Emirp because 17 as well as 71 are Prime.
|
| 13 |
+
In this problem, you have to decide whether a number N is Non-prime or Prime or Emirp. Assume
|
| 14 |
+
that 1 < N < 1000000.
|
| 15 |
+
Interestingly, Emirps are not new to NTU students. We have been boarding 199 and 179 buses for
|
| 16 |
+
quite a long time!
|
| 17 |
+
Input
|
| 18 |
+
Input consists of several lines specifying values for N.
|
| 19 |
+
Output
|
| 20 |
+
For each N given in the input, output should contain one of the following:
|
| 21 |
+
1. ‘N is not prime.’, if N is not a Prime number.
|
| 22 |
+
2. ‘N is prime.’, if N is Prime and N is not Emirp.
|
| 23 |
+
3. ‘N is emirp.’, if N is Emirp.
|
| 24 |
+
Sample Input
|
| 25 |
+
17
|
| 26 |
+
18
|
| 27 |
+
19
|
| 28 |
+
179
|
| 29 |
+
199
|
| 30 |
+
Sample Output
|
| 31 |
+
17 is emirp.
|
| 32 |
+
18 is not prime.
|
| 33 |
+
19 is prime.
|
| 34 |
+
179 is emirp.
|
| 35 |
+
199 is emirp.
|
10242.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10242
|
| 6 |
+
Fourth Point!!
|
| 7 |
+
Given are the (x, y) coordinates of the endpoints of two adjacent sides of a parallelogram. Find the
|
| 8 |
+
(x, y) coordinates of the fourth point.
|
| 9 |
+
Input
|
| 10 |
+
Each line of input contains eight floating point numbers: the (x, y) coordinates of one of the endpoints
|
| 11 |
+
of the first side followed by the (x, y) coordinates of the other endpoint of the first side, followed by the
|
| 12 |
+
(x, y) coordinates of one of the endpoints of the second side followed by the (x, y) coordinates of the
|
| 13 |
+
other endpoint of the second side. All coordinates are in meters, to the nearest mm. All coordinates
|
| 14 |
+
are between −10000 and +10000. Input is terminated by end of file.
|
| 15 |
+
Output
|
| 16 |
+
For each line of input, print the (x, y) coordinates of the fourth point of the parallelogram in meters,
|
| 17 |
+
to the nearest mm, separated by a single space.
|
| 18 |
+
Sample Input
|
| 19 |
+
0.000 0.000 0.000 1.000 0.000 1.000 1.000 1.000
|
| 20 |
+
1.000 0.000 3.500 3.500 3.500 3.500 0.000 1.000
|
| 21 |
+
1.866 0.000 3.127 3.543 3.127 3.543 1.412 3.145
|
| 22 |
+
Sample Output
|
| 23 |
+
1.000 0.000
|
| 24 |
+
-2.500 -2.500
|
| 25 |
+
0.151 -0.398
|
10252.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10252
|
| 6 |
+
Common Permutation
|
| 7 |
+
Given two strings of lowercase letters, a and b, print the longest string x of lowercase letters such
|
| 8 |
+
that there is a permutation of x that is a subsequence of a and there is a permutation of x that is a
|
| 9 |
+
subsequence of b.
|
| 10 |
+
Input
|
| 11 |
+
Input file contains several lines of input. Consecutive two lines make a set of input. That means in the
|
| 12 |
+
input file line 1 and 2 is a set of input, line 3 and 4 is a set of input and so on. The first line of a pair
|
| 13 |
+
contains a and the second contains b. Each string is on a separate line and consists of at most 1000
|
| 14 |
+
lowercase letters.
|
| 15 |
+
Output
|
| 16 |
+
For each set of input, output a line containing x. If several x satisfy the criteria above, choose the first
|
| 17 |
+
one in alphabetical order.
|
| 18 |
+
Sample Input
|
| 19 |
+
pretty
|
| 20 |
+
women
|
| 21 |
+
walking
|
| 22 |
+
down
|
| 23 |
+
the
|
| 24 |
+
street
|
| 25 |
+
Sample Output
|
| 26 |
+
e
|
| 27 |
+
nw
|
| 28 |
+
et
|
10268.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10268
|
| 6 |
+
498-bis
|
| 7 |
+
Looking throw the “Online Judge’s Problem Set Archive” I found a very interesting problem number
|
| 8 |
+
498, titled “Polly the Polynomial”. Frankly speaking, I did not solve it, but I derived from it this
|
| 9 |
+
problem.
|
| 10 |
+
Everything in this problem is a derivative of something from 498. In particular, 498 was “... designed
|
| 11 |
+
to help you remember ... basic algebra skills, make the world a better place, etc., etc.”. This problem
|
| 12 |
+
is designed to help you remember basic derivation algebra skills, increase the speed in which world
|
| 13 |
+
becomes a better place, etc., etc.
|
| 14 |
+
In 498 you had to evaluate the values of polynomial
|
| 15 |
+
a0xn + a1xn−1 + . . . + an−1x + an.
|
| 16 |
+
In this problem you should evaluate its derivative. Remember that derivative is defined as
|
| 17 |
+
a0nxn−1 + a1(n −1)xn−2 + . . . + an−1.
|
| 18 |
+
All the input and output data will fit into integer, i.e. its absolute value will be less than 231.
|
| 19 |
+
Input
|
| 20 |
+
Your program should accept an even number of lines of text. Each pair of lines will represent one
|
| 21 |
+
problem. The first line will contain one integer - a value for x. The second line will contain a list of
|
| 22 |
+
integers a0, a1, ..., an−1, an, which represent a set of polynomial coefficients.
|
| 23 |
+
Input is terminated by <EOF>.
|
| 24 |
+
Output
|
| 25 |
+
For each pair of lines, your program should evaluate the derivative of polynomial for the given value x
|
| 26 |
+
and output it in a single line.
|
| 27 |
+
Sample Input
|
| 28 |
+
7
|
| 29 |
+
1 -1
|
| 30 |
+
2
|
| 31 |
+
1 1 1
|
| 32 |
+
Sample Output
|
| 33 |
+
1
|
| 34 |
+
5
|
10409.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10409
|
| 6 |
+
Die Game
|
| 7 |
+
Life is not easy. Sometimes it is beyond your control. Now, as contestants of
|
| 8 |
+
ACM ICPC, you might be just tasting the bitter of life. But don’t worry! Do
|
| 9 |
+
not look only on the dark side of life, but look also on the bright side. Life
|
| 10 |
+
may be an enjoyable game of chance, like throwing dice. Do or die! Then, at
|
| 11 |
+
last, you might be able to find the route to victory.
|
| 12 |
+
This problem comes from a game using a die. By the way, do you know a
|
| 13 |
+
die? It has nothing to do with ”death.” A die is a cubic object with six faces,
|
| 14 |
+
each of which represents a different number from one to six and is marked
|
| 15 |
+
with the corresponding number of spots. Since it is usually used in pair, ”a
|
| 16 |
+
die” is a rarely used word. You might have heard a famous phrase ”the die is cast,” though.
|
| 17 |
+
When a game starts, a die stands still on a flat table. During the game, the die is tumbled in all
|
| 18 |
+
directions by the dealer. You will win the game if you can predict the number seen on the top face at
|
| 19 |
+
the time when the die stops tumbling.
|
| 20 |
+
Now you are requested to write a program that simulates the rolling of a die. For simplicity, we
|
| 21 |
+
assume that the die neither slips nor jumps but just rolls on the table in four directions, that is, north,
|
| 22 |
+
east, south, and west. At the beginning of every game, the dealer puts the die at the center of the
|
| 23 |
+
table and adjusts its direction so that the numbers one, two, and three are seen on the top, north, and
|
| 24 |
+
west faces, respectively. For the other three faces, we do not explicitly specify anything but tell you
|
| 25 |
+
the golden rule: the sum of the numbers on any pair of opposite faces is always seven.
|
| 26 |
+
Your program should accept a sequence of commands, each of which is either “north”, “east”,
|
| 27 |
+
“south”, or “west”. A “north” command tumbles the die down to north, that is, the top face becomes
|
| 28 |
+
the new north, the north becomes the new bottom, and so on. More precisely, the die is rotated around
|
| 29 |
+
its north bottom edge to the north direction and the rotation angle is 90 degrees. Other commands also
|
| 30 |
+
tumble the die accordingly to their own directions. Your program should calculate the number finally
|
| 31 |
+
shown on the top after performing the commands in the sequence. Note that the table is sufficiently
|
| 32 |
+
large and the die never falls off during the game.
|
| 33 |
+
Input
|
| 34 |
+
The input consists of one or more command sequences, each of which corresponds to a single game. The
|
| 35 |
+
first line of a command sequence contains a positive integer, representing the number of the following
|
| 36 |
+
command lines in the sequence. You may assume that this number is less than or equal to 1024. A line
|
| 37 |
+
containing a zero indicates the end of the input. Each command line includes a command that is one
|
| 38 |
+
of ‘north’, ‘east’, ‘south’, and ‘west’. You may assume that no white space occurs in any lines.
|
| 39 |
+
Output
|
| 40 |
+
For each command sequence, output one line containing solely the number on the top face at the time
|
| 41 |
+
when the game is finished.
|
| 42 |
+
Sample Input
|
| 43 |
+
1
|
| 44 |
+
north
|
| 45 |
+
3
|
| 46 |
+
north
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
## Page 2
|
| 50 |
+
|
| 51 |
+
east
|
| 52 |
+
south
|
| 53 |
+
0
|
| 54 |
+
Sample Output
|
| 55 |
+
5
|
| 56 |
+
1
|
10415.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10415
|
| 6 |
+
Eb Alto Saxophone Player
|
| 7 |
+
Do you like saxophone? I have a Eb Alto Saxophone, shown on the right.
|
| 8 |
+
My fingers move A LOT when playing some music, and I’m quite
|
| 9 |
+
interested in how many times each finger PRESS the button. Assume
|
| 10 |
+
that the music is composed of only 8 kinds of note. They are: C D E
|
| 11 |
+
F G A B in one octave and C D E F G A B in a higher octave. We
|
| 12 |
+
use c,d,e,f,g,a,b,C,D,E,F,G,A,B to represent them. The fingers I use for
|
| 13 |
+
each note are:
|
| 14 |
+
• c: finger 2∼4, 7∼10
|
| 15 |
+
• d: finger 2∼4, 7∼9
|
| 16 |
+
• e: finger 2∼4, 7, 8
|
| 17 |
+
• f: finger 2∼4, 7
|
| 18 |
+
• g: finger 2∼4
|
| 19 |
+
• a: finger 2, 3
|
| 20 |
+
• b: finger 2
|
| 21 |
+
• C: finger 3
|
| 22 |
+
• D: finger 1∼4, 7∼9
|
| 23 |
+
• E: finger 1∼4, 7, 8
|
| 24 |
+
• F: finger 1∼4, 7
|
| 25 |
+
• G: finger 1∼4
|
| 26 |
+
• A: finger 1∼3
|
| 27 |
+
• B: finger 1∼2
|
| 28 |
+
(Note that every finger is controlling a specified button, different fingers are controlling different
|
| 29 |
+
buttons.)
|
| 30 |
+
Write a program to help count the number of times each finger presses the button. A finger presses
|
| 31 |
+
a button if it is needed in a note, but not used in the last note. Also, if it is the first note, every finger
|
| 32 |
+
required presses the button.
|
| 33 |
+
Input
|
| 34 |
+
The first line of the input is a single integer t (1 ≤t ≤1000), indicating the number of test
|
| 35 |
+
cases.
|
| 36 |
+
For each case, there is only one line containing the song.
|
| 37 |
+
The only allowed characters are
|
| 38 |
+
{‘c’,‘d’,‘e’,‘f’,‘g’,‘a’,‘b’, ‘C',‘D’,‘E’,‘F’,‘G’,‘A’,‘B’}. There are at most 200 notes in a song, and the song
|
| 39 |
+
maybe empty.
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
## Page 2
|
| 43 |
+
|
| 44 |
+
Output
|
| 45 |
+
For each test case, print 10 numbers indicating the number of presses for each finger. Numbers are
|
| 46 |
+
separated by a single space.
|
| 47 |
+
Sample Input
|
| 48 |
+
3
|
| 49 |
+
cdefgab
|
| 50 |
+
BAGFEDC
|
| 51 |
+
CbCaDCbCbCCbCbabCCbCbabae
|
| 52 |
+
Sample Output
|
| 53 |
+
0 1 1 1 0 0 1 1 1 1
|
| 54 |
+
1 1 1 1 0 0 1 1 1 0
|
| 55 |
+
1 8 10 2 0 0 2 2 1 0
|
10420.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10420
|
| 6 |
+
List of Conquests
|
| 7 |
+
In Act I, Leporello is telling Donna Elvira about his master’s long list of conquests:
|
| 8 |
+
“This is the list of the beauties my master has loved, a list I’ve made out myself: take
|
| 9 |
+
a look, read it with me.
|
| 10 |
+
In Italy six hundred and forty, in Germany two hundred and
|
| 11 |
+
thirty-one, a hundred in France, ninety-one in Turkey; but in Spain already a thousand and
|
| 12 |
+
three! Among them are country girls, waiting-maids, city beauties; there are countesses,
|
| 13 |
+
baronesses, marchionesses, princesses: women of every rank, of every size, of every age.”
|
| 14 |
+
(Madamina, il catalogo questo)
|
| 15 |
+
As Leporello records all the “beauties” Don Giovanni “loved” in chronological order, it is very
|
| 16 |
+
troublesome for him to present his master’s conquest to others because he needs to count the number
|
| 17 |
+
of “beauties” by their nationality each time. You are to help Leporello to count.
|
| 18 |
+
Input
|
| 19 |
+
The input consists of at most 2000 lines. The first line contains a number n, indicating that there will
|
| 20 |
+
be n more lines. Each following line, with at most 75 characters, contains a country (the first word)
|
| 21 |
+
and the name of a woman (the rest of the words in the line) Giovanni loved. You may assume that the
|
| 22 |
+
name of all countries consist of only one word.
|
| 23 |
+
Output
|
| 24 |
+
The output consists of lines in alphabetical order. Each line starts with the name of a country, followed
|
| 25 |
+
by the total number of women Giovanni loved in that country, separated by a space.
|
| 26 |
+
Sample Input
|
| 27 |
+
3
|
| 28 |
+
Spain Donna Elvira
|
| 29 |
+
England Jane Doe
|
| 30 |
+
Spain Donna Anna
|
| 31 |
+
Sample Output
|
| 32 |
+
England 1
|
| 33 |
+
Spain 2
|
10642.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10642
|
| 6 |
+
Can You Solve It?
|
| 7 |
+
First take a look at the following picture. In this picture, each circle has a coordinate according to
|
| 8 |
+
Cartesian Coordinate System. You can move from one circle to another following the path denoted by
|
| 9 |
+
forward arrow symbols. To go from a source circle to a destination circle,
|
| 10 |
+
total_number_of_step(s)_needed = number_of_intermediate_circles_you_pass + 1
|
| 11 |
+
For example, to go from (0, 3) to (3, 0) you have to pass two intermediate circles (1, 2) and (2, 1). So,
|
| 12 |
+
in this case, total number of steps needed is 2 + 1 = 3. In this problem, you are to calculate number of
|
| 13 |
+
step(s) needed for a given source circle and a destination circle. You can assume that, it is not possible
|
| 14 |
+
to go back using the reverse direction of the arrows.
|
| 15 |
+
Input
|
| 16 |
+
The first line in the input is the number of test cases n (0 < n ≤500) to handle. Following there are n
|
| 17 |
+
lines each containing four integers (0 ≤each_integer ≤100000) the first pair of which represents the
|
| 18 |
+
coordinates of the source circle and the other represents that of the destination circle. The coordinates
|
| 19 |
+
are listed in a form (x, y).
|
| 20 |
+
Output
|
| 21 |
+
For each pair of integers your program should output the case number first and then the number of
|
| 22 |
+
step(s) to reach the destination from the source. You may assume that it is always possible to reach
|
| 23 |
+
the destination circle from the source circle.
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
## Page 2
|
| 27 |
+
|
| 28 |
+
Sample Input
|
| 29 |
+
3
|
| 30 |
+
0 0 0 1
|
| 31 |
+
0 0 1 0
|
| 32 |
+
0 0 0 2
|
| 33 |
+
Sample Output
|
| 34 |
+
Case 1: 1
|
| 35 |
+
Case 2: 2
|
| 36 |
+
Case 3: 3
|
10783.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10783
|
| 6 |
+
Odd Sum
|
| 7 |
+
Given a range [a, b], you are to find the summation of all the odd integers in this range. For example,
|
| 8 |
+
the summation of all the odd integers in the range [3, 9] is 3 + 5 + 7 + 9 = 24.
|
| 9 |
+
Input
|
| 10 |
+
There can be at multiple test cases.
|
| 11 |
+
The first line of input gives you the number of test cases, T
|
| 12 |
+
(1 ≤T ≤100). Then T test cases follow. Each test case consists of 2 integers a and b (0 ≤a ≤b ≤100)
|
| 13 |
+
in two separate lines.
|
| 14 |
+
Output
|
| 15 |
+
For each test case you are to print one line of output – the serial number of the test case followed by
|
| 16 |
+
the summation of the odd integers in the range [a, b].
|
| 17 |
+
Sample Input
|
| 18 |
+
2
|
| 19 |
+
1
|
| 20 |
+
5
|
| 21 |
+
3
|
| 22 |
+
5
|
| 23 |
+
Sample Output
|
| 24 |
+
Case 1: 9
|
| 25 |
+
Case 2: 8
|
10812.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10812
|
| 6 |
+
Beat the Spread!
|
| 7 |
+
Superbowl Sunday is nearly here. In order to pass the time waiting for
|
| 8 |
+
the half-time commercials and wardrobe malfunctions, the local hackers
|
| 9 |
+
have organized a betting pool on the game. Members place their bets
|
| 10 |
+
on the sum of the two final scores, or on the absolute difference between
|
| 11 |
+
the two scores.
|
| 12 |
+
Given the winning numbers for each type of bet, can you deduce
|
| 13 |
+
the final scores?
|
| 14 |
+
Input
|
| 15 |
+
The first line of input contains n, the number of test cases. n lines
|
| 16 |
+
follow, each representing a test case.
|
| 17 |
+
Each test case gives s and d,
|
| 18 |
+
non-negative integers representing the sum and (absolute) difference between the two final scores.
|
| 19 |
+
Output
|
| 20 |
+
For each test case, output a line giving the two final scores, largest first. If there are no such scores,
|
| 21 |
+
output a line containing “impossible”. Recall that football scores are always non-negative integers.
|
| 22 |
+
Sample Input
|
| 23 |
+
2
|
| 24 |
+
40 20
|
| 25 |
+
20 40
|
| 26 |
+
Sample Output
|
| 27 |
+
30 10
|
| 28 |
+
impossible
|
10908.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10908
|
| 6 |
+
Largest Square
|
| 7 |
+
Given a rectangular grid of characters you have to find out the length of a side of the largest square such
|
| 8 |
+
that all the characters of the square are same and the center [intersecting point of the two diagonals]
|
| 9 |
+
of the square is at location (r, c). The height and width of the grid is M and N respectively. Upper
|
| 10 |
+
left corner and lower right corner of the grid will be denoted by (0, 0) and (M −1, N −1) respectively.
|
| 11 |
+
Consider the grid of characters given below. Given the location (1, 2) the length of a side of the largest
|
| 12 |
+
square is 3.
|
| 13 |
+
abbbaaaaaa
|
| 14 |
+
abbbaaaaaa
|
| 15 |
+
abbbaaaaaa
|
| 16 |
+
aaaaaaaaaa
|
| 17 |
+
aaaaaaaaaa
|
| 18 |
+
aaccaaaaaa
|
| 19 |
+
aaccaaaaaa
|
| 20 |
+
Input
|
| 21 |
+
The input starts with a line containing a single integer T (< 21). This is followed by T test cases. The
|
| 22 |
+
first line of each of them will contain three integers M, N and Q (< 21) separated by a space where
|
| 23 |
+
M, N denotes the dimension of the grid. Next follows M lines each containing N characters. Finally,
|
| 24 |
+
there will be Q lines each containing two integers r and c. The value of M and N will be at most 100.
|
| 25 |
+
Output
|
| 26 |
+
For each test case in the input produce Q + 1 lines of output. In the first line print the value of M, N
|
| 27 |
+
and Q in that order separated by single space. In the next Q lines, output the length of a side of the
|
| 28 |
+
largest square in the corresponding grid for each (r, c) pair in the input.
|
| 29 |
+
Sample Input
|
| 30 |
+
1
|
| 31 |
+
7 10 4
|
| 32 |
+
abbbaaaaaa
|
| 33 |
+
abbbaaaaaa
|
| 34 |
+
abbbaaaaaa
|
| 35 |
+
aaaaaaaaaa
|
| 36 |
+
aaaaaaaaaa
|
| 37 |
+
aaccaaaaaa
|
| 38 |
+
aaccaaaaaa
|
| 39 |
+
1 2
|
| 40 |
+
2 4
|
| 41 |
+
4 6
|
| 42 |
+
5 2
|
| 43 |
+
Sample Output
|
| 44 |
+
7 10 4
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
## Page 2
|
| 48 |
+
|
| 49 |
+
3
|
| 50 |
+
1
|
| 51 |
+
5
|
| 52 |
+
1
|
10922.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10922
|
| 6 |
+
2 the 9s
|
| 7 |
+
A well-known trick to know if an integer N is a multiple of nine is to compute the sum S of its digits.
|
| 8 |
+
If S is a multiple of nine, then so is N. This is a recursive test, and the depth of the recursion needed
|
| 9 |
+
to obtain the answer on N is called the 9-degree of N.
|
| 10 |
+
Your job is, given a positive number N, determine if it is a multiple of nine and, if it is, its 9-degree.
|
| 11 |
+
Input
|
| 12 |
+
The input is a file such that each line contains a positive number. A line containing the number 0 is
|
| 13 |
+
the end of the input. The given numbers can contain up to 1000 digits.
|
| 14 |
+
Output
|
| 15 |
+
The output of the program shall indicate, for each input number, if it is a multiple of nine, and in case
|
| 16 |
+
it is, the value of its nine-degree. See the sample output for an example of the expected formatting of
|
| 17 |
+
the output.
|
| 18 |
+
Sample Input
|
| 19 |
+
999999999999999999999
|
| 20 |
+
9
|
| 21 |
+
9999999999999999999999999999998
|
| 22 |
+
0
|
| 23 |
+
Sample Output
|
| 24 |
+
999999999999999999999 is a multiple of 9 and has 9-degree 3.
|
| 25 |
+
9 is a multiple of 9 and has 9-degree 1.
|
| 26 |
+
9999999999999999999999999999998 is not a multiple of 9.
|
10929.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10929
|
| 6 |
+
You can say 11
|
| 7 |
+
Your job is, given a positive number N, determine if it is a multiple of eleven.
|
| 8 |
+
Input
|
| 9 |
+
The input is a file such that each line contains a positive number. A line containing the number ‘0’ is
|
| 10 |
+
the end of the input. The given numbers can contain up to 1000 digits.
|
| 11 |
+
Output
|
| 12 |
+
The output of the program shall indicate, for each input number, if it is a multiple of eleven or not.
|
| 13 |
+
Sample Input
|
| 14 |
+
112233
|
| 15 |
+
30800
|
| 16 |
+
2937
|
| 17 |
+
323455693
|
| 18 |
+
5038297
|
| 19 |
+
112234
|
| 20 |
+
0
|
| 21 |
+
Sample Output
|
| 22 |
+
112233 is a multiple of 11.
|
| 23 |
+
30800 is a multiple of 11.
|
| 24 |
+
2937 is a multiple of 11.
|
| 25 |
+
323455693 is a multiple of 11.
|
| 26 |
+
5038297 is a multiple of 11.
|
| 27 |
+
112234 is not a multiple of 11.
|
10931.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
10931
|
| 6 |
+
Parity
|
| 7 |
+
We define the parity of an integer n as the sum of the bits in binary representation computed modulo
|
| 8 |
+
two. As an example, the number 21 = 101012 has three 1s in its binary representation so it has parity
|
| 9 |
+
3(mod2), or 1.
|
| 10 |
+
In this problem you have to calculate the parity of an integer 1 ≤I ≤2147483647.
|
| 11 |
+
Input
|
| 12 |
+
Each line of the input has an integer I and the end of the input is indicated by a line where I = 0 that
|
| 13 |
+
should not be processed.
|
| 14 |
+
Output
|
| 15 |
+
For each integer I in the inputt you should print a line ‘The parity of B is P (mod 2).’, where B
|
| 16 |
+
is the binary representation of I.
|
| 17 |
+
Sample Input
|
| 18 |
+
1
|
| 19 |
+
2
|
| 20 |
+
10
|
| 21 |
+
21
|
| 22 |
+
0
|
| 23 |
+
Sample Output
|
| 24 |
+
The parity of 1 is 1 (mod 2).
|
| 25 |
+
The parity of 10 is 1 (mod 2).
|
| 26 |
+
The parity of 1010 is 2 (mod 2).
|
| 27 |
+
The parity of 10101 is 3 (mod 2).
|
11005.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
11005
|
| 6 |
+
Cheapest Base
|
| 7 |
+
When printing text on paper we need ink. But not every character needs the same amount of ink to
|
| 8 |
+
print: letters such as ’W’, ’M’ and ’8’ are more expensive than thinner letters as ’i’, ’c’ and ’1’. In this
|
| 9 |
+
problem we will evaluate the cost of printing numbers in several bases.
|
| 10 |
+
As you know, numbers can be expressed in several different bases. Well known bases are binary (base
|
| 11 |
+
2; digits 0 and 1), decimal (base 10; digits 0 to 9) and hexadecimal (base 16; digits 0 to 9 and letters A
|
| 12 |
+
to F). For the general base n we will use the first n characters of the string “0123456789ABCDEFGHI-
|
| 13 |
+
JKLMNOPQRSTUVWXYZ”, which means the highest base in this problem is 36. The lowest base is
|
| 14 |
+
of course 2.
|
| 15 |
+
Every character from this string has an associated cost, represented by an integer value between 1
|
| 16 |
+
and 128. The cost to print a number in a certain base is the sum of the costs of all characters needed
|
| 17 |
+
to represent that number. For the numbers given in the input, you will have to calculate the cheapest
|
| 18 |
+
base(s) to represent this number in. Numbers in any base are printed without leading zeros.
|
| 19 |
+
Input
|
| 20 |
+
The input has less than 25 test cases. The first line of input file denotes this number of test cases. The
|
| 21 |
+
description of every test case is given below:
|
| 22 |
+
The first 4 lines of every case contain 9 integers each: the costs of the 36 characters in the order
|
| 23 |
+
given above. Then follows the number of queries on a line by itself. Every query appears on a line by
|
| 24 |
+
itself and is formed by a number between 0 and 2000000000 in decimal format.
|
| 25 |
+
Output
|
| 26 |
+
For every case in the input, print one line ‘Case X:’, without the quotes, where X is the case number
|
| 27 |
+
starting from 1.
|
| 28 |
+
For every query within a case print one line ‘Cheapest base(s) for number Y :’ followed by the
|
| 29 |
+
cheapest base(s) in increasing order, separated by one space. Y is the query in decimal format. Print
|
| 30 |
+
a blank line between cases.
|
| 31 |
+
The numbers in the second sample output are actually all in one line just like the first sample
|
| 32 |
+
output. Due to lack of horizontal space they are shown broken in two lines.
|
| 33 |
+
Sample Input
|
| 34 |
+
2
|
| 35 |
+
10 8 12 13 15 13 13 16 9
|
| 36 |
+
11 18 24 21 23 23 23 13 15
|
| 37 |
+
17 33 21 23 27 26 27 19 4
|
| 38 |
+
22 18 30 30 24 16 26 21 21
|
| 39 |
+
5
|
| 40 |
+
98329921
|
| 41 |
+
12345
|
| 42 |
+
800348
|
| 43 |
+
14
|
| 44 |
+
873645
|
| 45 |
+
1 1 1 1 1 1 1 1 1
|
| 46 |
+
1 1 1 1 1 1 1 1 1
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
## Page 2
|
| 50 |
+
|
| 51 |
+
1 1 1 1 1 1 1 1 1
|
| 52 |
+
1 1 1 1 1 1 1 1 1
|
| 53 |
+
4
|
| 54 |
+
0
|
| 55 |
+
1
|
| 56 |
+
10
|
| 57 |
+
100
|
| 58 |
+
Sample Output
|
| 59 |
+
Case 1:
|
| 60 |
+
Cheapest base(s) for number 98329921: 24
|
| 61 |
+
Cheapest base(s) for number 12345: 13 31
|
| 62 |
+
Cheapest base(s) for number 800348: 31
|
| 63 |
+
Cheapest base(s) for number 14: 13
|
| 64 |
+
Cheapest base(s) for number 873645: 22
|
| 65 |
+
Case 2:
|
| 66 |
+
Cheapest base(s) for number 0: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
| 67 |
+
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
| 68 |
+
Cheapest base(s) for number 1: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
| 69 |
+
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
| 70 |
+
Cheapest base(s) for number 10: 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
| 71 |
+
26 27 28 29 30 31 32 33 34 35 36
|
| 72 |
+
Cheapest base(s) for number 100: 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
| 73 |
+
26 27 28 29 30 31 32 33 34 35 36
|
11063.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
11063
|
| 6 |
+
B2-Sequence
|
| 7 |
+
A B2-Sequence is a sequence of positive integers 1 ≤b1 < b2 < b3 . . . such that all pairwise sums bi +bj,
|
| 8 |
+
where i ≤j, are different.
|
| 9 |
+
Your task is to determine if a given sequence is a B2-Sequence or not.
|
| 10 |
+
Input
|
| 11 |
+
Each test case starts with 2 ≤N ≤100, the number of elements in a sequence. Next line will have N
|
| 12 |
+
integers, representing the value of each element in the sequence. Each element bi is an integer such that
|
| 13 |
+
bi ≤10000. There is a blank line after each test case. The input is terminated by end of file (EOF).
|
| 14 |
+
Output
|
| 15 |
+
For each test case you must print the number of the test case, starting from 1, and a message indicating
|
| 16 |
+
if the corresponding sequence it is a B2-Sequence or not. See the sample output below. After each test
|
| 17 |
+
case you must print a blank line.
|
| 18 |
+
Sample Input
|
| 19 |
+
4
|
| 20 |
+
1 2 4 8
|
| 21 |
+
4
|
| 22 |
+
3 7 10 14
|
| 23 |
+
Sample Output
|
| 24 |
+
Case #1: It is a B2-Sequence.
|
| 25 |
+
Case #2: It is not a B2-Sequence.
|
11150.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
11150
|
| 6 |
+
Cola
|
| 7 |
+
You see the following special offer by the convenience store:
|
| 8 |
+
“A bottle of Choco Cola for every 3 empty bottles returned”
|
| 9 |
+
Now you decide to buy some (say N) bottles of cola from the store. You would like to know how
|
| 10 |
+
you can get the most cola from them.
|
| 11 |
+
The figure below shows the case where N = 8. Method 1 is the standard way: after finishing your 8
|
| 12 |
+
bottles of cola, you have 8 empty bottles. Take 6 of them and you get 2 new bottles of cola. Now after
|
| 13 |
+
drinking them you have 4 empty bottles, so you take 3 of them to get yet another new cola. Finally,
|
| 14 |
+
you have only 2 bottles in hand, so you cannot get new cola any more. Hence, you have enjoyed 8 + 2
|
| 15 |
+
+ 1 = 11 bottles of cola.
|
| 16 |
+
You can actually do better! In Method 2, you first borrow an empty bottle from your friend (?! Or
|
| 17 |
+
the storekeeper??), then you can enjoy 8 + 3 + 1 = 12 bottles of cola! Of course, you will have to
|
| 18 |
+
return your remaining empty bottle back to your friend.
|
| 19 |
+
Input
|
| 20 |
+
Input consists of several lines, each containing an integer N (1 ≤N ≤200).
|
| 21 |
+
Output
|
| 22 |
+
For each case, your program should output the maximum number of bottles of cola you can enjoy. You
|
| 23 |
+
may borrow empty bottles from others, but if you do that, make sure that you have enough bottles
|
| 24 |
+
afterwards to return to them.
|
| 25 |
+
Note: Drinking too much cola is bad for your health, so... don’t try this at home!! :-)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
## Page 2
|
| 29 |
+
|
| 30 |
+
Sample Input
|
| 31 |
+
8
|
| 32 |
+
Sample Output
|
| 33 |
+
12
|
11321.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
11321
|
| 6 |
+
Sort! Sort!! And Sort!!!
|
| 7 |
+
Hmm! Here you are asked to do a simple sorting. You will be given N numbers and a positive integer
|
| 8 |
+
M. You will have to sort the N numbers in ascending order of their modulo M value. If there is a tie
|
| 9 |
+
between an odd number and an even number (that is their modulo M value is the same) then the odd
|
| 10 |
+
number will precede the even number. If there is a tie between two odd numbers (that is their modulo
|
| 11 |
+
M value is the same) then the larger odd number will precede the smaller odd number and if there
|
| 12 |
+
is a tie between two even numbers (that is their modulo M value is the same) then the smaller even
|
| 13 |
+
number will precede the larger even number.
|
| 14 |
+
For remainder value of negative numbers follow the rule of C programming language: A negative
|
| 15 |
+
number can never have modulus greater than zero. E.g. -100 MOD 3 = -1, -100 MOD 4 = 0, etc.
|
| 16 |
+
Input
|
| 17 |
+
The input file contains 20 sets of inputs. Each set starts with two integers N (0 < N ≤10000) and
|
| 18 |
+
M (0 < M ≤10000) which denotes how many numbers are within this set. Each of the next N lines
|
| 19 |
+
contains one number each. These numbers should all fit in 32-bit signed integer. Input is terminated
|
| 20 |
+
by a line containing two zeroes.
|
| 21 |
+
Output
|
| 22 |
+
For each set of input produce N + 1 lines of outputs. The first line of each set contains the value of N
|
| 23 |
+
and M. The next N lines contain N numbers, sorted according to the rules mentioned above. Print
|
| 24 |
+
the last two zeroes of the input file in the output file also.
|
| 25 |
+
Sample Input
|
| 26 |
+
15 3
|
| 27 |
+
1
|
| 28 |
+
2
|
| 29 |
+
3
|
| 30 |
+
4
|
| 31 |
+
5
|
| 32 |
+
6
|
| 33 |
+
7
|
| 34 |
+
8
|
| 35 |
+
9
|
| 36 |
+
10
|
| 37 |
+
11
|
| 38 |
+
12
|
| 39 |
+
13
|
| 40 |
+
14
|
| 41 |
+
15
|
| 42 |
+
0 0
|
| 43 |
+
Sample Output
|
| 44 |
+
15 3
|
| 45 |
+
15
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
## Page 2
|
| 49 |
+
|
| 50 |
+
9
|
| 51 |
+
3
|
| 52 |
+
6
|
| 53 |
+
12
|
| 54 |
+
13
|
| 55 |
+
7
|
| 56 |
+
1
|
| 57 |
+
4
|
| 58 |
+
10
|
| 59 |
+
11
|
| 60 |
+
5
|
| 61 |
+
2
|
| 62 |
+
8
|
| 63 |
+
14
|
| 64 |
+
0 0
|
11332.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
11332
|
| 6 |
+
Summing Digits
|
| 7 |
+
For a positive integer n, let f(n) denote the sum
|
| 8 |
+
of the digits of n when represented in base 10.
|
| 9 |
+
It is easy to see that the sequence of numbers
|
| 10 |
+
n, f(n), f(f(n)), f(f(f(n))), . . . eventually becomes a
|
| 11 |
+
single digit number that repeats forever. Let this sin-
|
| 12 |
+
gle digit be denoted g(n).
|
| 13 |
+
For example, consider n = 1234567892. Then:
|
| 14 |
+
f(n) = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 2 = 47
|
| 15 |
+
f(f(n)) = 4 + 7 = 11
|
| 16 |
+
f(f(f(n))) = 1 + 1 = 2
|
| 17 |
+
Therefore, g(1234567892) = 2.
|
| 18 |
+
Input
|
| 19 |
+
Each line of input contains a single positive integer n
|
| 20 |
+
at most 2,000,000,000. Input is terminated by n = 0
|
| 21 |
+
which should not be processed.
|
| 22 |
+
Output
|
| 23 |
+
For each such integer, you are to output a single line
|
| 24 |
+
containing g(n).
|
| 25 |
+
Sample Input
|
| 26 |
+
2
|
| 27 |
+
11
|
| 28 |
+
47
|
| 29 |
+
1234567892
|
| 30 |
+
0
|
| 31 |
+
Sample Output
|
| 32 |
+
2
|
| 33 |
+
2
|
| 34 |
+
2
|
| 35 |
+
2
|
11349.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
11349
|
| 6 |
+
Symmetric Matrix
|
| 7 |
+
You‘re given a square matrix M. Elements of this matrix are Mij : {0 < i < n, 0 < j < n}. In this
|
| 8 |
+
problem you’ll have to find out whether the given matrix is symmetric or not.
|
| 9 |
+
Definition: Symmetric matrix is such a matrix that all elements of it are non-negative and symmetric
|
| 10 |
+
with relation to the center of this matrix. Any other matrix is considered to be non-symmetric. For
|
| 11 |
+
example:
|
| 12 |
+
M =
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
5
|
| 16 |
+
1
|
| 17 |
+
3
|
| 18 |
+
2
|
| 19 |
+
0
|
| 20 |
+
2
|
| 21 |
+
3
|
| 22 |
+
1
|
| 23 |
+
5
|
| 24 |
+
|
| 25 |
+
is symmetric
|
| 26 |
+
M =
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
5
|
| 30 |
+
1
|
| 31 |
+
3
|
| 32 |
+
2
|
| 33 |
+
0
|
| 34 |
+
2
|
| 35 |
+
0
|
| 36 |
+
1
|
| 37 |
+
5
|
| 38 |
+
|
| 39 |
+
is not symmetric, because 3 ̸= 0
|
| 40 |
+
All you have to do is to find whether the matrix is symmetric or not. Elements of a matrix given
|
| 41 |
+
in the input are −232 ≤Mij ≤232 and 0 < n ≤100.
|
| 42 |
+
Input
|
| 43 |
+
First line of input contains number of test cases T ≤300. Then T test cases follow each described in
|
| 44 |
+
the following way. The first line of each test case contains n – the dimension of square matrix. Then
|
| 45 |
+
n lines follow each of then containing row i. Row contains exactly n elements separated by a space
|
| 46 |
+
character. j-th number in row i is the element Mij of matrix you have to process.
|
| 47 |
+
Output
|
| 48 |
+
For each test case output one line ‘Test #t: S’. Where t is the test number starting from 1. Line S is
|
| 49 |
+
equal to ‘Symmetric’ if matrix is symmetric and ‘Non-symmetric’ in any other case.
|
| 50 |
+
Sample Input
|
| 51 |
+
2
|
| 52 |
+
N = 3
|
| 53 |
+
5 1 3
|
| 54 |
+
2 0 2
|
| 55 |
+
3 1 5
|
| 56 |
+
N = 3
|
| 57 |
+
5 1 3
|
| 58 |
+
2 0 2
|
| 59 |
+
0 1 5
|
| 60 |
+
Sample Output
|
| 61 |
+
Test #1: Symmetric.
|
| 62 |
+
Test #2: Non-symmetric.
|
11417.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
11417
|
| 6 |
+
GCD
|
| 7 |
+
Given the value of N, you will have to find the value of G. The definition of G is given below:
|
| 8 |
+
G =
|
| 9 |
+
i<N
|
| 10 |
+
∑
|
| 11 |
+
i=1
|
| 12 |
+
j≤N
|
| 13 |
+
∑
|
| 14 |
+
j=i+1
|
| 15 |
+
GCD(i, j)
|
| 16 |
+
Here GCD(i, j) means the greatest common divisor of integer i and integer j.
|
| 17 |
+
For those who have trouble understanding summation notation, the meaning of G is given in the
|
| 18 |
+
following code:
|
| 19 |
+
G=0;
|
| 20 |
+
for(i=1;i<N;i++)
|
| 21 |
+
for(j=i+1;j<=N;j++)
|
| 22 |
+
{
|
| 23 |
+
G+=GCD(i,j);
|
| 24 |
+
}
|
| 25 |
+
/*Here GCD() is a function that finds
|
| 26 |
+
the greatest common divisor of the two
|
| 27 |
+
input numbers*/
|
| 28 |
+
Input
|
| 29 |
+
The input file contains at most 100 lines of inputs. Each line contains an integer N (1 < N < 501).
|
| 30 |
+
The meaning of N is given in the problem statement. Input is terminated by a line containing a single
|
| 31 |
+
zero. This zero should not be processed.
|
| 32 |
+
Output
|
| 33 |
+
For each line of input produce one line of output. This line contains the value of G for corresponding
|
| 34 |
+
N.
|
| 35 |
+
Sample Input
|
| 36 |
+
10
|
| 37 |
+
100
|
| 38 |
+
500
|
| 39 |
+
0
|
| 40 |
+
Sample Output
|
| 41 |
+
67
|
| 42 |
+
13015
|
| 43 |
+
442011
|
11461.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
11461
|
| 6 |
+
Square Numbers
|
| 7 |
+
A square number is an integer number whose square root is also an integer. For example 1, 4, 81 are
|
| 8 |
+
some square numbers. Given two numbers a and b you will have to find out how many square numbers
|
| 9 |
+
are there between a and b (inclusive).
|
| 10 |
+
Input
|
| 11 |
+
The input file contains at most 201 lines of inputs. Each line contains two integers a and b (0 < a ≤
|
| 12 |
+
b ≤100000). Input is terminated by a line containing two zeroes. This line should not be processed.
|
| 13 |
+
Output
|
| 14 |
+
For each line of input produce one line of output. This line contains an integer which denotes how
|
| 15 |
+
many square numbers are there between a and b (inclusive).
|
| 16 |
+
Sample Input
|
| 17 |
+
1 4
|
| 18 |
+
1 10
|
| 19 |
+
0 0
|
| 20 |
+
Sample Output
|
| 21 |
+
2
|
| 22 |
+
3
|
118.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
118
|
| 6 |
+
Mutant Flatworld Explorers
|
| 7 |
+
Robotics, robot motion planning, and machine learning are areas that cross the boundaries of many of
|
| 8 |
+
the subdisciplines that comprise Computer Science: artificial intelligence, algorithms and complexity,
|
| 9 |
+
electrical and mechanical engineering to name a few.
|
| 10 |
+
In addition, robots as “turtles” (inspired by
|
| 11 |
+
work by Papert, Abelson, and diSessa) and as “beeper-pickers” (inspired by work by Pattis) have been
|
| 12 |
+
studied and used by students as an introduction to programming for many years.
|
| 13 |
+
This problem involves determining the position of a robot exploring a pre-Columbian flat world.
|
| 14 |
+
Given the dimensions of a rectangular grid and a sequence of robot positions and instructions, you
|
| 15 |
+
are to write a program that determines for each sequence of robot positions and instructions the final
|
| 16 |
+
position of the robot.
|
| 17 |
+
A robot position consists of a grid coordinate (a pair of integers: x-coordinate followed by y-
|
| 18 |
+
coordinate) and an orientation (N,S,E,W for north, south, east, and west). A robot instruction is a string
|
| 19 |
+
of the letters ‘L’, ‘R’, and ‘F’ which represent, respectively, the instructions:
|
| 20 |
+
• Left: the robot turns left 90 degrees and remains on the current grid point.
|
| 21 |
+
• Right: the robot turns right 90 degrees and remains on the current grid point.
|
| 22 |
+
• Forward: the robot moves forward one grid point in the direction of the current orientation and
|
| 23 |
+
mantains the same orientation.
|
| 24 |
+
The direction North corresponds to the direction from grid point (x, y) to grid point (x, y + 1).
|
| 25 |
+
Since the grid is rectangular and bounded, a robot that moves “off” an edge of the grid is lost forever.
|
| 26 |
+
However, lost robots leave a robot “scent” that prohibits future robots from dropping off the world at
|
| 27 |
+
the same grid point. The scent is left at the last grid position the robot occupied before disappearing
|
| 28 |
+
over the edge. An instruction to move “off” the world from a grid point from which a robot has been
|
| 29 |
+
previously lost is simply ignored by the current robot.
|
| 30 |
+
Input
|
| 31 |
+
The first line of input is the upper-right coordinates of the rectangular world, the lower-left coordinates
|
| 32 |
+
are assumed to be 0,0.
|
| 33 |
+
The remaining input consists of a sequence of robot positions and instructions (two lines per robot).
|
| 34 |
+
A position consists of two integers specifying the initial coordinates of the robot and an orientation
|
| 35 |
+
(N,S,E,W), all separated by white space on one line. A robot instruction is a string of the letters ‘L’, ‘R’,
|
| 36 |
+
and ‘F’ on one line.
|
| 37 |
+
Each robot is processed sequentially, i.e., finishes executing the robot instructions before the next
|
| 38 |
+
robot begins execution.
|
| 39 |
+
Input is terminated by end-of-file.
|
| 40 |
+
You may assume that all initial robot positions are within the bounds of the specified grid. The
|
| 41 |
+
maximum value for any coordinate is 50. All instruction strings will be less than 100 characters in
|
| 42 |
+
length.
|
| 43 |
+
Output
|
| 44 |
+
For each robot position/instruction in the input, the output should indicate the final grid position and
|
| 45 |
+
orientation of the robot. If a robot falls off the edge of the grid the word ‘LOST’ should be printed after
|
| 46 |
+
the position and orientation.
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
## Page 2
|
| 50 |
+
|
| 51 |
+
Sample Input
|
| 52 |
+
5 3
|
| 53 |
+
1 1 E
|
| 54 |
+
RFRFRFRF
|
| 55 |
+
3 2 N
|
| 56 |
+
FRRFLLFFRRFLL
|
| 57 |
+
0 3 W
|
| 58 |
+
LLFFFLFLFL
|
| 59 |
+
Sample Output
|
| 60 |
+
1 1 E
|
| 61 |
+
3 3 N LOST
|
| 62 |
+
2 3 S
|
12019.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
12019
|
| 6 |
+
Doom’s Day Algorithm
|
| 7 |
+
No. Doom’s day algorithm is not a method to compute which day the world will end. It is an algorithm
|
| 8 |
+
created by the mathematician John Horton Conway, to calculate which day of the week (Monday,
|
| 9 |
+
Tuesday, etc.) corresponds to a certain date.
|
| 10 |
+
This algorithm is based in the idea of the doomsday, a certain day of the week which always
|
| 11 |
+
occurs in the same dates. For example, 4/4 (the 4th of April), 6/6 (the 6th of June), 8/8 (the 8th of
|
| 12 |
+
August), 10/10 (the 10th of October) and 12/12 (the 12th of December) are dates which always occur
|
| 13 |
+
in doomsday. All years have their own doomsday.
|
| 14 |
+
In year 2011, doomsday is Monday. So all of 4/4, 6/6, 8/8, 10/10 and 12/12 are Mondays. Using
|
| 15 |
+
that information, you can easily compute any other date. For example, the 13th of December 2011 will
|
| 16 |
+
be Tuesday, the 14th of December 2011 will be Wednesday, etc.
|
| 17 |
+
Other days which occur on doomsday are 5/9, 9/5, 7/11 and 11/7. Also, in leap years, we have
|
| 18 |
+
the following doomsdays: 1/11 (the 11th of January) and 2/22 (the 22nd of Febrary), and in non-leap
|
| 19 |
+
years 1/10 and 2/21.
|
| 20 |
+
Given a date of year 2011, you have to compute which day of the week it occurs.
|
| 21 |
+
Input
|
| 22 |
+
The input can contain different test cases. The first line of the input indicates the number of test cases.
|
| 23 |
+
For each test case, there is a line with two numbers: M D. M represents the month (from 1 to 12)
|
| 24 |
+
and D represents the day (from 1 to 31). The date will always be valid.
|
| 25 |
+
Output
|
| 26 |
+
For each test case, you have to output the day of the week where that date occurs in 2011. The days
|
| 27 |
+
of the week will be: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
|
| 28 |
+
Sample Input
|
| 29 |
+
8
|
| 30 |
+
1 6
|
| 31 |
+
2 28
|
| 32 |
+
4 5
|
| 33 |
+
5 26
|
| 34 |
+
8 1
|
| 35 |
+
11 1
|
| 36 |
+
12 25
|
| 37 |
+
12 31
|
| 38 |
+
Sample Output
|
| 39 |
+
Thursday
|
| 40 |
+
Monday
|
| 41 |
+
Tuesday
|
| 42 |
+
Thursday
|
| 43 |
+
Monday
|
| 44 |
+
Tuesday
|
| 45 |
+
Sunday
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
## Page 2
|
| 49 |
+
|
| 50 |
+
Saturday
|
272.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
272
|
| 6 |
+
TEX Quotes
|
| 7 |
+
TEX is a typesetting language developed by Donald Knuth. It takes source text together with a few
|
| 8 |
+
typesetting instructions and produces, one hopes, a beautiful document. Beautiful documents use “
|
| 9 |
+
and ” to delimit quotations, rather than the mundane " which is what is provided by most keyboards.
|
| 10 |
+
Keyboards typically do not have an oriented double-quote, but they do have a left-single-quote ` and
|
| 11 |
+
a right-single-quote '.
|
| 12 |
+
Check your keyboard now to locate the left-single-quote key ` (sometimes
|
| 13 |
+
called the “backquote key”) and the right-single-quote key ' (sometimes called the “apostrophe” or just
|
| 14 |
+
“quote”). Be careful not to confuse the left-single-quote ` with the “backslash” key \. TEX lets the user
|
| 15 |
+
type two left-single-quotes `` to create a left-double-quote “ and two right-single-quotes '' to create
|
| 16 |
+
a right-double-quote ”. Most typists, however, are accustomed to delimiting their quotations with the
|
| 17 |
+
un-oriented double-quote ".
|
| 18 |
+
If the source contained
|
| 19 |
+
"To be or not to be," quoth the bard, "that is the question."
|
| 20 |
+
then the typeset document produced by TEX would not contain the desired form:
|
| 21 |
+
“To be or not to be,” quoth the bard, “that is the question.”
|
| 22 |
+
In order to produce the desired form, the source file must contain the sequence:
|
| 23 |
+
``To be or not to be,'' quoth the bard, ``that is the question.''
|
| 24 |
+
You are to write a program which converts text containing double-quote (") characters into text
|
| 25 |
+
that is identical except that double-quotes have been replaced by the two-character sequences required
|
| 26 |
+
by TEX for delimiting quotations with oriented double-quotes. The double-quote (") characters should
|
| 27 |
+
be replaced appropriately by either `` if the " opens a quotation and by '' if the " closes a quotation.
|
| 28 |
+
Notice that the question of nested quotations does not arise: The first " must be replaced by ``, the
|
| 29 |
+
next by '', the next by ``, the next by '', the next by ``, the next by '', and so on.
|
| 30 |
+
Input
|
| 31 |
+
Input will consist of several lines of text containing an even number of double-quote (") characters.
|
| 32 |
+
Input is ended with an end-of-file character.
|
| 33 |
+
Output
|
| 34 |
+
The text must be output exactly as it was input except that:
|
| 35 |
+
• the first " in each pair is replaced by two ` characters: `` and
|
| 36 |
+
• the second " in each pair is replaced by two ' characters: ''.
|
| 37 |
+
Sample Input
|
| 38 |
+
"To be or not to be," quoth the Bard, "that
|
| 39 |
+
is the question".
|
| 40 |
+
The programming contestant replied: "I must disagree.
|
| 41 |
+
To `C' or not to `C', that is The Question!"
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
## Page 2
|
| 45 |
+
|
| 46 |
+
Sample Output
|
| 47 |
+
``To be or not to be,'' quoth the Bard, ``that
|
| 48 |
+
is the question''.
|
| 49 |
+
The programming contestant replied: ``I must disagree.
|
| 50 |
+
To `C' or not to `C', that is The Question!''
|
299.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
299
|
| 6 |
+
Train Swapping
|
| 7 |
+
At an old railway station, you may still encounter one of the last remaining “train swappers”. A train
|
| 8 |
+
swapper is an employee of the railroad, whose sole job it is to rearrange the carriages of trains.
|
| 9 |
+
Once the carriages are arranged in the optimal order, all the train driver has to do, is drop the
|
| 10 |
+
carriages off, one by one, at the stations for which the load is meant.
|
| 11 |
+
The title “train swapper” stems from the first person who performed this task, at a station close to
|
| 12 |
+
a railway bridge. Instead of opening up vertically, the bridge rotated around a pillar in the center of
|
| 13 |
+
the river. After rotating the bridge 90 degrees, boats could pass left or right.
|
| 14 |
+
The first train swapper had discovered that the bridge could be operated with at most two carriages
|
| 15 |
+
on it. By rotating the bridge 180 degrees, the carriages switched place, allowing him to rearrange the
|
| 16 |
+
carriages (as a side effect, the carriages then faced the opposite direction, but train carriages can move
|
| 17 |
+
either way, so who cares).
|
| 18 |
+
Now that almost all train swappers have died out, the railway company would like to automate
|
| 19 |
+
their operation. Part of the program to be developed, is a routine which decides for a given train the
|
| 20 |
+
least number of swaps of two adjacent carriages necessary to order the train. Your assignment is to
|
| 21 |
+
create that routine.
|
| 22 |
+
Input
|
| 23 |
+
The input contains on the first line the number of test cases (N). Each test case consists of two input
|
| 24 |
+
lines. The first line of a test case contains an integer L, determining the length of the train (0 ≤L ≤50).
|
| 25 |
+
The second line of a test case contains a permutation of the numbers 1 through L, indicating the current
|
| 26 |
+
order of the carriages. The carriages should be ordered such that carriage 1 comes first, then 2, etc.
|
| 27 |
+
with carriage L coming last.
|
| 28 |
+
Output
|
| 29 |
+
For each test case output the sentence: ‘Optimal train swapping takes S swaps.’ where S is an
|
| 30 |
+
integer.
|
| 31 |
+
Sample Input
|
| 32 |
+
3
|
| 33 |
+
3
|
| 34 |
+
1 3 2
|
| 35 |
+
4
|
| 36 |
+
4 3 2 1
|
| 37 |
+
2
|
| 38 |
+
2 1
|
| 39 |
+
Sample Output
|
| 40 |
+
Optimal train swapping takes 1 swaps.
|
| 41 |
+
Optimal train swapping takes 6 swaps.
|
| 42 |
+
Optimal train swapping takes 1 swaps.
|
490.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
490
|
| 6 |
+
Rotating Sentences
|
| 7 |
+
In “Rotating Sentences,” you are asked to rotate a series of input sentences 90 degrees clockwise. So
|
| 8 |
+
instead of displaying the input sentences from left to right and top to bottom, your program will display
|
| 9 |
+
them from top to bottom and right to left.
|
| 10 |
+
Input
|
| 11 |
+
As input to your program, you will be given a maximum of 100 sentences, each not exceeding 100
|
| 12 |
+
characters long. Legal characters include: newline, space, any punctuation characters, digits, and lower
|
| 13 |
+
case or upper case English letters. (NOTE: Tabs are not legal characters.)
|
| 14 |
+
Output
|
| 15 |
+
The output of the program should have the last sentence printed out vertically in the leftmost column;
|
| 16 |
+
the first sentence of the input would subsequently end up at the rightmost column.
|
| 17 |
+
Sample Input
|
| 18 |
+
Rene Decartes once said,
|
| 19 |
+
"I think, therefore I am."
|
| 20 |
+
Sample Output
|
| 21 |
+
"R
|
| 22 |
+
Ie
|
| 23 |
+
n
|
| 24 |
+
te
|
| 25 |
+
h
|
| 26 |
+
iD
|
| 27 |
+
ne
|
| 28 |
+
kc
|
| 29 |
+
,a
|
| 30 |
+
r
|
| 31 |
+
tt
|
| 32 |
+
he
|
| 33 |
+
es
|
| 34 |
+
r
|
| 35 |
+
eo
|
| 36 |
+
fn
|
| 37 |
+
oc
|
| 38 |
+
re
|
| 39 |
+
e
|
| 40 |
+
s
|
| 41 |
+
Ia
|
| 42 |
+
i
|
| 43 |
+
ad
|
| 44 |
+
m,
|
| 45 |
+
.
|
| 46 |
+
"
|
948.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
## Page 1
|
| 4 |
+
|
| 5 |
+
948
|
| 6 |
+
Fibonaccimal Base
|
| 7 |
+
The well known Fibonacci sequence is obtained by starting with 0 and 1 and then adding the two last
|
| 8 |
+
numbers to get the next one. For example the third number in the sequence is 1 (1=1+0), the forth is
|
| 9 |
+
2 (2=1+1), the fifth is 3 (3=2+1) and so on.
|
| 10 |
+
i
|
| 11 |
+
0
|
| 12 |
+
1
|
| 13 |
+
2
|
| 14 |
+
3
|
| 15 |
+
4
|
| 16 |
+
5
|
| 17 |
+
6
|
| 18 |
+
7
|
| 19 |
+
8
|
| 20 |
+
9
|
| 21 |
+
Fib(i)
|
| 22 |
+
0
|
| 23 |
+
1
|
| 24 |
+
1
|
| 25 |
+
2
|
| 26 |
+
3
|
| 27 |
+
5
|
| 28 |
+
8
|
| 29 |
+
13
|
| 30 |
+
21
|
| 31 |
+
34
|
| 32 |
+
Figure 1 - The first numbers in the Fibonacci sequence
|
| 33 |
+
The sequence appears on many things in our life, in nature, and has a great significance. Among
|
| 34 |
+
other things, do you know that all positive integer numbers can be represented as a sum of numbers in
|
| 35 |
+
the Fibonacci sequence? More than that, all positive integers can be represented as a sum of a set of
|
| 36 |
+
Fibonacci numbers, that is, numbers from the sequence, without repetition. For example: 13 can be the
|
| 37 |
+
sum of the sets {13}, {5,8} or {2,3,8} and 17 is represented by {1,3,13} or {1,3,5,8}. Since all numbers
|
| 38 |
+
have this property (do you want to try to prove this for yourself?) this set could be a nice way to use as
|
| 39 |
+
a "base" to represent the number. But, as we have seen, some numbers have more than one set whose
|
| 40 |
+
sum is the number. How can we solve that? Simple! If we add the constraint that the sets cannot
|
| 41 |
+
have two consecutive Fibonacci numbers, than we have a unique representation for each number! This
|
| 42 |
+
restriction is because the sum of any two consecutive Fibonacci numbers is just the following Fibonacci
|
| 43 |
+
number.
|
| 44 |
+
Now that we know all this we can prepare a nice way to represent any positive integer. We will use
|
| 45 |
+
a binary sequence (just zeros and ones) to do that. For example, 17 = 1 + 3 + 13 (remember that no
|
| 46 |
+
two consecutive Fibonacci numbers can be used). Let’s write a zero for each Fibonacci number that is
|
| 47 |
+
not used and one for each one that is used, starting at the right. Then, 17 = 100101. See figure 2 for a
|
| 48 |
+
detailed explanation. In this representation we should not have zeros at the left, this is, we should only
|
| 49 |
+
write starting with the first one. In order for you to understand better, note that in this scheme, not
|
| 50 |
+
using two consecutive Fibonacci numbers means that the binary sequence will not have two consecutive
|
| 51 |
+
ones. When we use this representation for a number we say that we are using the Fibonaccimal base,
|
| 52 |
+
and we write it like 17 = 100101 (fib).
|
| 53 |
+
17 =
|
| 54 |
+
1
|
| 55 |
+
0
|
| 56 |
+
0
|
| 57 |
+
1
|
| 58 |
+
0
|
| 59 |
+
1
|
| 60 |
+
13+3+1 =
|
| 61 |
+
13
|
| 62 |
+
8
|
| 63 |
+
5
|
| 64 |
+
3
|
| 65 |
+
2
|
| 66 |
+
1
|
| 67 |
+
Figure 2 - Explaining the representation of 17 in Fibonaccimal base
|
| 68 |
+
Given a set of numbers in decimal base, your task is to write them in the Fibonaccimal base.
|
| 69 |
+
Input
|
| 70 |
+
The first line of input contains a single number N, representing the quantity of numbers that follow
|
| 71 |
+
(1 ≤N ≤500).
|
| 72 |
+
Than follow exactly N lines, each one containing a single positive integer smaller than 100 000 000.
|
| 73 |
+
These numbers can come in any order.
|
| 74 |
+
Output
|
| 75 |
+
You should output a single line for each of the N integers in the input, with the format ‘DEC BASE
|
| 76 |
+
= FIB BASE (fib)’. DEC BASE is the original number in decimal base and FIB BASE is its
|
| 77 |
+
representation in Fibonaccimal base. See the sample output for an example.
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
## Page 2
|
| 81 |
+
|
| 82 |
+
Sample Input
|
| 83 |
+
10
|
| 84 |
+
1
|
| 85 |
+
2
|
| 86 |
+
3
|
| 87 |
+
4
|
| 88 |
+
5
|
| 89 |
+
6
|
| 90 |
+
7
|
| 91 |
+
8
|
| 92 |
+
9
|
| 93 |
+
10
|
| 94 |
+
Sample Output
|
| 95 |
+
1 = 1 (fib)
|
| 96 |
+
2 = 10 (fib)
|
| 97 |
+
3 = 100 (fib)
|
| 98 |
+
4 = 101 (fib)
|
| 99 |
+
5 = 1000 (fib)
|
| 100 |
+
6 = 1001 (fib)
|
| 101 |
+
7 = 1010 (fib)
|
| 102 |
+
8 = 10000 (fib)
|
| 103 |
+
9 = 10001 (fib)
|
| 104 |
+
10 = 10010 (fib)
|