MooresLaw
SRM 287 · 2006-02-04 · by misof
Problem Statement
Moore's law is a well-known prediction of the growth of computing power over time. This is the formulation we will use in this problem: The speed of new computers grows exponentially and doubles every 18 months. In this problem we will assume that reality precisely obeys this law.
Suppose that you have a hard computational task that would take 14 years to complete on a current computer. Surprisingly, starting its computation as soon as possible is not the best you can do. A better solution: Wait for 18 months and buy a better computer. It will be twice as fast, and therefore solve the task in 7 years. You would have the result 8.5 years from now. In the best possible solution you should wait for slightly over 4 years. The computer you'll be able to buy then will solve the task in approximately 2.2 years, giving a total of 6.2 years.
You have a computational task you want to solve as quickly as possible. You will be given an
Notes
- Your return value must have an absolute or relative error less than 1e-9.
- The computation speed growth is a continuous exponential function satisfying the property from the problem statement.
Constraints
- years will be between 1 and 1,000,000,000, inclusive.
14 Returns: 6.2044816339207705
The example from the problem statement.
3 Returns: 2.870893001916099
47 Returns: 8.82533252835082
123 Returns: 10.907221008843223
1 Returns: 1.0
Submissions are judged against all 44 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class MooresLaw with a public method double shortestComputationTime(int years) · 44 test cases · 2 s / 256 MB per case