Blue Bridge Cup - machines breeding 6th C language group C final question 4

Topic narrative:

Title: Robot Reproduction

X galaxies robot can automatically replicate itself. They use a year's time can replicate the two themselves, and then lose the ability to replicate.
X galaxies year will elect a new born robot sent into space. That is, if X 5 Galaxy original robot,
after 1 year Total is: 5 + 9 = 14
Number of 2 years is: 5 + 9 + 17 = 31

If you have a robot probe through s n the total number of years later, you can calculate how much of the original robot do?

Data Format:

An input line and two numbers n s, separated by a space, meaning as above. n is not greater than 100, s is not more than 50 bits.

Requirements output line, an integer that represents the number of robot initially.

For example:
a user input:
231

The program should output:
5

Another example:
a user input:
97 2218388550399401452619230609499

The program should output:
8

Resources for:
peak memory consumption <512M
the CPU consumption <1000ms


Please strictly follow the requirements of output, not superfluous to print something like: "Please enter ..." unwanted content.

All source code in a single file, through debugging, submit the copy source.

Note: main function needs to return 0
Note: Use only ANSI C / ANSI C ++ standard, do not call a special function depends on the build environment or operating system.
Note: all dependent functions must explicitly #include <xxx>, can not be provided by the project source file header files commonly omitted.

When you submit, pay attention to select the desired type of compiler.

 

Analysis: The problem is not difficult to find a math problem to find the law on it

We can assume that the initial number of robots x 

Corresponding to the year and the number is represented as follows:

1: x + 2x-1 = 3x-1 = (2 ^ 2-1) (x-1) +2

2: x + 2x-1 + 2 (2x-1) -1 = 7x-4 = (2 ^ 3-1) (x-1) +3

3: x + 2x-1 + 2 (2x-1) -1 + 2 (2 (2x-1) -1) -1 = 15x-11 = (2 ^ 4-1) (x-1) +4

........

And so on, the number of the n: sum = (2 ^ (n + 1) -1) (x-1) + n + 1 

Further simplification can be x = (sum-n-1) / (2 ^ (n + 1) -1) +1

Direct knock code to get the law on the line, relatively brief, the test can be AC

C ++ code as follows:

#include <bits / STDC ++ H.>
the using namespace STD;
int main () {
int n-; double sum; // sum value needed here because the problem of double storage requirement is not more than 50 s, the larger
cin >> n> > SUM;

Double POW = P (2, n-+. 1);
int X = (SUM-n--. 1) / (. 1-P) + 1'd;
COUT << X;
return 0;
}

 

Guess you like

Origin www.cnblogs.com/wanganwen/p/12286052.html