您的位置:首页 > 其它

HDU 2899 Strange fuction

2016-07-21 14:46 260 查看
题目:

Description

Now, here is a fuction:

F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)

Can you find the minimum value when x is between 0 and 100.

Input

The first line of the input contains an integer T(1<=T<=100) which means the number of test cases. Then T lines follow, each line has only one real numbers Y.(0 < Y <1e10)

Output

Just the minimum value (accurate up to 4 decimal places),when x is between 0 and 100.

Sample Input

2
100
200


Sample Output

-74.4291
-178.8534


这个题目和DU 2199 Can you solve this equation?差不多,不过没有了昨天那个EPS的精度的问题。

很容易看出来,F(x)在区间(0,100)就是先递减后递增,利用这个作为二分查找时选择左右的依据即可。

代码:

#include<stdio.h>

int main()
{
int t;
scanf("%d", &t);
double y;
while (t--)
{
scanf("%lf", &y);
double low = 0, high = 100;
double m;
double mmm;
while (low + 0.0000001 < high)
{
m = (low + high) / 2;
mmm = m*m*m;
if (((42 * mmm + 48 * m*m)*mmm + 21 * m*m + 10 * m)>y)high = m;
else low = m;
}
printf("%.4lf\n", (6*m+8)*mmm*mmm+7*mmm+5*m*m-y*m);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: