H- Bose-Einstein condensed stateTime
limit:MS
Memory Limit:32768KB
64bit IO Form At:%i64d &%i64u Submit Status
Description
Now, this 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 of the line have only one real numbers y. (0 < y <1e10)
Output
Just the minimum value (accurate up to 4 decimal places) while X is between 0 and 100.
Sample Input
Sample Output
Ideas:
Because it is the equation is determined, the problem is to get the minimum value of the equation, after the derivation we find that the reciprocal is incremented, and this equation at the beginning of the reciprocal is negative, it is at the time of the 0 of the function is able to take the minimum value, so we have to use the binary search method, Find the point in X that can make the function 0 (because the function is an increment function, so you can find it with a binary), and then take the value of the found X into the equation of the function, which is the minimum value required! first of all, do not go blind binary search, because the variable memory with the int type is required, so first the range of X is as narrow as possible, at the beginning I also want to be x in the range of 0~100 to find there is no guide function for 0 points, who knows the super memory, So I'm going to find a way to take the value of the 42*n*n*n*n*n*n+48*n*n*n*n*n+21*n*n+10*n to the maximum when the maximum value of the y is a little larger, and not ultra-memory, so that any Y value can be found to make the function of 0 points, not super memory, will be able to do our general idea of the problem!
Code:
#include <stdio.h> #include <string.h> #include <queue> #include <iostream> #include <map > #include <algorithm>using namespace std;double y; Double f (double N) {return 42*n*n*n*n*n*n+48*n*n*n*n*n+21*n*n+10*n;} Double Erfen (double left,double right) {double Mid;while (right-left>1e-7) {mid= (right+left)/2;if (f (mid)-y<1e-7 ) {Left=mid;} else {right=mid;}} return right;} int main () {int t;scanf ("%d", &t), while (t--) {scanf ("%lf", &y);d ouble t=erfen (0.0,18.0);d ouble b=6*t*t*t*t*t*t *t+8*t*t*t*t*t*t+7*t*t*t+5*t*t-y*t;printf ("%.4lf\n", b); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
ACM Freshman Practice Competition-the third------H-Bose-Einstein condensed State "binary search"