Title Description
Now, this is a fuction:
F (x) = 6 * x^7+8x^6+7x^3+5x^2-yx (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
2
100
200
Sample Output
-74.4291
-178.8534
Effect
To find the minimum value of the function in the interval [0,100]
Ideas
Derivative of the function f ' (x) =42* x^6+48x^5+21x^2+10x-y
, and then derivative of the derivative function, it is found that the derivative function is monotonically increasing.
It is concluded that the minimum value of the function is
the root of x^6+48x^5+21x^2+10*x=y.
The program should first determine whether the root is within the [0,100] interval, divided into three kinds of situations discussed.
The code of this problem is not very different from the first question, it is the first problem of deformation
AC Code
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<cmath>
using namespace std;
double f_d(double res)
{
returnRes*Res*Res*Res*Res*Res* the +Res*Res*Res*Res*Res* - +Res*Res* + +Res* Ten;
}
double f(double res,double y){
returnRes*Res*Res*Res*Res*Res*Res*6 +Res*Res*Res*Res*Res*Res*8 +Res*Res*Res*7 +Res*Res* 5-Res*y;
}
int main(){
//freopen("date.in", "r", stdin);
//freopen("date.out", "w", stdout);
int T;
double a;
double b,e,tem;
cin>>T;
for(int i=0;i<T;i++){
cin>>a;
if(f_d(100)<=a)
cout<<fixed<<setprecision(4)<<f(100,a)<<endl;
else
if(f_d(0)>=a)
cout<<fixed<<setprecision(4)<<f(0,a)<<endl;
else{
-
b = 0 , e = 100 tem Span class= "pun" >= 50 ;
while (fabs(f_d(tem) - a) >= 1e-7)
if (f_d(tem)>a){
e = tem;
tem = (b + e) / 2;
}
else{
b = tem;
tem = (b + e) / 2;
}
cout<<fixed<<setprecision(4)<<f(tem,a)<<endl;
}
}
}
From for notes (Wiz)
ACM Course Practice 2--1002