Trigonometric Optimization
Time limit2sMemory limit128 MB
Choose positive integers x, y, z summing to S to optimize sin/cos(x)+sin/cos(y)+sin/cos(z), rounded to 10 decimals.
- Level
Medium4 of 10
- Topics
- Math, Brute force, Greedy
- Solved
- No attempts yet
Problem
Many problems that arise in practice can be stated as optimization problems: we must maximize or minimize a so-called criterion function subject to some constraints.
Consider the following trigonometric optimization problem. Maximize or minimize the criterion function
subject to the constraint , where , , are the variables and is a given parameter. All of , , , are natural numbers (positive integers, so ). Each of the functions , , is a trigonometric function — either or — and its argument is measured in radians.
Write a program that solves this trigonometric optimization problem.
Input
The input consists of 5 lines.
- Line 1 describes the function and contains either
sinorcos. - Line 2 describes the function in the same format.
- Line 3 describes the function in the same format.
- Line 4 contains either
minormax. If it ismin, the criterion function must be minimized; if it ismax, it must be maximized. - Line 5 contains the parameter ().
Output
Print a single line containing the optimal value of the criterion function: its maximum when line 4 is max, or its minimum when line 4 is min, taken over all natural numbers , , with .
Print the value rounded to exactly 10 digits after the decimal point (format %.10f).