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.
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
1 //0MS 224K 590 B G++ 2 /* 3 4 题意: 5 给出一关系式: 6 F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100) 7 和y的值,求x在范围(0,100)内时F(x)能取得的最小值 8 9 二分法: 10 很容易可以看出函数F(x)在(0,100)内是先减后增的,故用二分法求其倒数的零值点,然后用零值 11 再代入原式即可求出最值 12 13 */ 14 #include<stdio.h> 15 #define e 1e-7 16 double fac(double a,double b) 17 { 18 return 6*a*a*a*a*a*a*a+8*a*a*a*a*a*a+7*a*a*a+5*a*a-b*a; 19 } 20 double fac0(double a,double b) 21 { 22 return 42*a*a*a*a*a*a+48*a*a*a*a*a+21*a*a+10*a-b; 23 } 24 int main(void) 25 { 26 int t; 27 double n; 28 scanf("%d",&t); 29 while(t--) 30 { 31 scanf("%lf",&n); 32 double l=0; 33 double r=100; 34 while(r-l>e){ 35 double mid=(l+r)/2; 36 if(fac0(mid,n)>0) r=mid; 37 else l=mid; 38 } 39 printf("%.4lf ",fac(r,n)); 40 } 41 return 0; 42 }