U
U
Umid2017-05-15 11:59:57
Programming
Umid, 2017-05-15 11:59:57

Is it possible to solve this problem?

Good afternoon.
The other day in the city (Tashkent) there was an Olympiad.
And the following task came across,
the only thing that confuses is that the input is a number in the range from 1 to 10 to the 18th degree (below is indicated).
And given only 2 seconds.
The result is checked by the machine, and substitutes a variety of values.
If a solution is possible, then please direct me to solve this problem.
68892fbeab104d22bcf8de38ada0cc45.jpg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mercury13, 2017-05-15
@DarCKoder

10 18 is a regular 64-bit integer. long longin C, longin Java, int64in Delphi.
Obviously, the task is translatable, the match is not only a match (they have a very ambiguous word), but also a matchstick. Moreover, it was either an automaton or a rare overbrain that translated, an example that doesn’t speak, and it’s frankly incomprehensible: either where the number 11 is located, or what is in the 11th position. We will solve the 2nd problem: what is in the 11th position.
1. Determine the number of digits (a simple cycle is enough for this) and what number this number has among N-digit numbers.
2. And now we find how many N-digit numbers there are from M matches. Recursive relation:
Q[N, M] = sum{k = 1..9} (Q[N−1, M−q(k)]), if N is the value we found, but not 1,
For the remaining N, the formula is the same, but the summation is 0…9.
q(0) = 6, q(1) = 2, q(2) = 5, etc. - number of matches in a figure.
Boundary condition: Q[0, 0] = 1, Q[0, M] = 0 for the remaining M.
Using the “arm-twisting method”, we also assume that for negative M all Q are equal to 0.
We solve the recurrence relation by dynamic programming.
3. And now the most interesting thing: using the dynamic programming table, find the number by number, starting with the highest.
For example, we have the 15th number. Let's skip the first step, trust me: it's the 4th two-digit, starting from zero.
2nd step.
Q[1,2] = 1
Q[1,3] = 1
Q[1,4] = 1
Q[1,5] = 3
Q[1,6] = 3
Q[1,7] = 1
Q[ 2,4] = 1
Q[2,5] = 2
Q[2,6] did not calculate, the main thing is prohibitively large.
Q[2,0]…Q[2,3] are equal to zero.
Subtract Q[2,4] - it turns out 3.
Subtract Q[2,5] - it turns out 1.
Subtract Q[2,6] - it doesn't work. In total, we have six matches, 1 remains.
3rd step, we work according to the number.
Zero, Q[1, 6−6] = 0. Remains 1.
One, Q[1, 6−2] = 1. Remains 0.
Two, Q[1, 6−5] = 0. Remains 0.
Three, Q[1, 6−5] = 0. Remains 0.
Four, Q[1, 6−4] = 1. Not subtracted, 2 matches remain, 1 sign and number 0. Write down the number 4.
Zero, Q[0, 2−5] = 0. Remains 0.
One, Q[0, 2−2] = 1. Not subtracted, 0 matches, 0 characters and number 0 remain. We write down the number 1.
We got 41 in total.

A
aslan7470, 2017-05-17
@aslan7470

It’s not necessary to count anything
for I from 0 to 9 in the I-th place, a number of one digit, which requires the I-th number of matches in the account,
change each of the entered digits of the position in this way

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question