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
题解:
咳咳,不要说为什么可以看出是三分,打表大法好(其实我是用了函数绘制工具)......然后直接套板子即可
1 #include <algorithm> 2 #include <iostream> 3 #include <cstdlib> 4 #include <cstring> 5 #include <cstdio> 6 #include <cmath> 7 #define RG register 8 #define il inline 9 using namespace std; 10 const double eps=1e-6; 11 double y; 12 double f(double x){ 13 return 6*x*x*x*x*x*x*x+8*x*x*x*x*x*x+7*x*x*x+5*x*x-y*x; 14 } 15 void work() 16 { 17 cin>>y; 18 double l=0,r=100,lmid,rmid; 19 while(l+eps<r){ 20 lmid=l+(r-l)/3;rmid=r-(r-l)/3; 21 if(f(lmid)>f(rmid))l=lmid; 22 else r=rmid; 23 } 24 printf("%.4lf ",f(l)); 25 } 26 27 int main() 28 { 29 int T;cin>>T; 30 while(T--) 31 work(); 32 return 0; 33 }