Strange fuctionTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total Submission (s): 4795 Accepted Submission (s): 3420
Problem Descriptionnow, 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.
Inputthe first line of the input contains an integer T (1<=t<=100) which means the number of test cases. Then T-lines follow, each of the line have only one real numbers y. (0 < y <1e10)
Outputjust the minimum value (accurate up to 4 decimal places) while X is between 0 and 100.
Sample Input
2100200
Sample Output
-74.4291-178.8534 Simple binary + Mathematics: two points after derivation to find the closest value to Y, at this time the original function is the smallest;#include <stdio.h> #include <math.h>double y;double Hanshu (double x)//original function value {return 6*pow (x,7) +8*pow (x,6) +7 *pow (x,3) +5*pow (x,2)-y*x;} Double Daoshu (double x)//Guide Value {return 42*pow (x,6) +48*pow (x,5) +21*pow (x,2) +10*x-y;} int main () {int n;scanf ("%d", &n), while (n--) {scanf ("%lf", &y), if (Y>=daoshu ()) printf ("%lf\n", Hanshu ( );d ouble Right =100,left=0;while ((right-left) >=1e-10)//dichotomy {double mid= (right+left)/2;if (Daoshu (mid) >0) Right=mid;elseleft=mid;} printf ("%.4lf\n", Hanshu (right));} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hdoj 2899 Strange fuction