TheArithmeticProgression
SRM 591 · 2013-06-25 · by gojira_tc
SRM 591 · 2013-06-25 · by gojira_tc · Simple Math
Problem Statement
Problem Statement
A triple (x, y, z) is called an arithmetic progression if the equality y - x = z - y holds.
You are given threeint s a, b and c. Your goal is to change the triple (a, b, c) into an arithmetic progression.
You are only allowed to change one of the three numbers.
The change must proceed as follows:
First, you choose a non-negative real (not necessarily integer) number r.
Then, you either add r to one of the three given numbers, or you subtract r from one of them. Return the minimum value of r which allows you to create an arithmetic progression.
You are given three
Constraints
- a will be between 0 and 1000, inclusive.
- b will be between 0 and 1000, inclusive.
- c will be between 0 and 1000, inclusive.
Examples
0)
0 1 2 Returns: 0.0
The triple (0, 1, 2) is an arithmetic progression. Thus, you can choose r = 0.0 and add or subtract it from any of the given numbers without changing the triple.
1)
0 2 1 Returns: 1.5
Note that while (0, 1, 2) is an arithmetic progression, you cannot rearrange the numbers within the triple. You can choose r = 1.5 and subtract it from b, obtaining the triple (0, 0.5, 1).
2)
3 2 1 Returns: 0.0
3)
4 4 8 Returns: 2.0
4)
1000 0 0 Returns: 500.0
Submissions are judged against all 61 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class TheArithmeticProgression with a public method double minimumChange(int a, int b, int c) · 61 test cases · 2 s / 256 MB per case