hdu 2899 Strange fuction (二分法)

时间:2022-05-19 05:55:16

Strange fuction

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2278    Accepted Submission(s): 1697

Problem 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
 
Author
Redow
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  2289 2298 2141 3400 1969 
 
 //0MS    224K    590 B    G++
/* 题意:
给出一关系式:
F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)
和y的值,求x在范围(0,100)内时F(x)能取得的最小值 二分法:
很容易可以看出函数F(x)在(0,100)内是先减后增的,故用二分法求其倒数的零值点,然后用零值
再代入原式即可求出最值 */
#include<stdio.h>
#define e 1e-7
double fac(double a,double b)
{
return *a*a*a*a*a*a*a+*a*a*a*a*a*a+*a*a*a+*a*a-b*a;
}
double fac0(double a,double b)
{
return *a*a*a*a*a*a+*a*a*a*a*a+*a*a+*a-b;
}
int main(void)
{
int t;
double n;
scanf("%d",&t);
while(t--)
{
scanf("%lf",&n);
double l=;
double r=;
while(r-l>e){
double mid=(l+r)/;
if(fac0(mid,n)>) r=mid;
else l=mid;
}
printf("%.4lf\n",fac(r,n));
}
return ;
}