原题传送门:http://acm.hdu.edu.cn/showproblem.php?pid=2899
Strange fuction
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3021 Accepted Submission(s): 2235
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
分析:首先分析这个函数单调性,对其求导得到42*x^6+48*x^5+21*x^2+10*x-y;很明显原函数0-100内先减后增大,那么一定存在一个x0,使得原函数最小,那么x0怎么求?
我们可以用一阶导数==0的时候,求得x0,问题就化为,用二分法求方程42*x^6+48*x^5+21*x^2+10*x-y = 0;时候的x0的值了,具体求法详见博客http://hellojyj.iteye.com/blog/2093672
//二分法求方程最值 HDU 2899 #include<cstdio> #include<cmath> double low,mid,high; int Y,t; using namespace std; double ff(double x,int y){ double result = 42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*x-y; return result; } double f(double x,int y){ double result = 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x; return result; } int main(){ scanf("%d",&t); while(t--){ scanf("%d",&Y); low = 0.0; high = 100.0; while(low<high) { mid = (low+high)/2; if(fabs(ff(mid,Y))<= 0.000001) { break; }else if(ff(mid,Y)>0) { high = mid; }else { low = mid; } } printf("%.4f\n",f(mid,Y)); } }
相关推荐
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
杭电ACMhdu1163
HDU1059的代码
hdu1001解题报告
hdu 1574 passed sorce
HDU的一题........HDU DP动态规
hdu acm 教案 搜索入门 hdu acm 教案 搜索入门
hdu2101AC代码
搜索 dfs 解题代码 hdu1241
hdu 5007 Post Robot 字符串枚举。 暴力一下就可以了。
hdu acm 教案 动态规划(1) hdu acm 教案 动态规划(1)
ACM HDU题目分类,我自己总结的大概只有十来个吧
hdu 1166线段树代码
HDU最全ac代码
hdu动态规划算法集锦
自己做的HDU ACM已经AC的题目
hdu题目分类
HDU图论题目分类
hdu-acm源代码(上百题)hdu-acm源代码、hdu-acm源代码hdu-acm源代码
Hdu 1237 解题代码