Mr.Lin and gradient descent

TimeLimit:100MS  MemoryLimit:128MB
64-bit integer IO format:%lld
未提交 | 登录后收藏
Problem Description

In machine learning, there is a class of problems called unconstrained optimization problems, and gradient descent is one of the most commonly used methods. Given a simple convex function, please answer the minimum value of this convex function according to the gradient descent algorithm.

I guess you probably won't have a gradient descent algorithm, so we'll give you a gradient descent algorithm that you can implement.

The first step of the algorithm, based on the point (x1, x2, …, xn) on the curve, we need to determine the gradient of the loss function at the current position. For each
xi, the gradient expression is as follows:

                                                                    image.png

In the second step of the algorithm, the step size is multiplied by the gradient of the loss function to obtain the distance at which the current position falls, that is,                                   

                                                         image.png

 

We can assume that α is any real number greater than 0 and less than 1, you can think α = 0.5.

In the third step of the algorithm, it is determined whether all θi, the distance of the gradient drop is less than ε, if all of them are less than ε, the algorithm terminates, and all current θi (i=0, 1, . . . n) is the final result. and currentimage.pngis the answer.

 

 

Otherwise go to step 4.

The fourth step of the algorithm updates all x. for xi, its update expression is as follows.    

                                                     image.png

After the update is complete, proceed to step 1.

For make the problem more simply, all the convex functions we give are quadratic functions and the points on a quadratic function. Please find the minimum value of the given convex function with an error precision less than 1e-6. 


上面都是废话,直接看这里

给你一个一元二次函数让你求最小值,保证a>0

Input

There multiple test cases in the input

for each test case contain one line means a quadratic function, guarantee the function is a convex function, and a point in curve(-200< xi < 200), separated by space

all coefficient are real number greater than 0

Output

For each test case output a real number means the minimum value of quadratic function. 

SampleInput
y=x^2 (2,4)
y=2*x^2+1 (3,19)
SampleOutput
0.000000
1.000000
Submit
题目统计信息详细
总AC数4
通过人数4
尝试人数7
总提交量11
AC率36.36%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: