首页 > 其他 > 详细

hdu 2899

时间:2014-08-07 19:14:30      阅读:466      评论:0      收藏:0      [点我收藏+]

 

Strange fuction

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3209    Accepted Submission(s): 2348


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.
 


 

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

 

代码如下:

<span style="font-size:14px;">#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define eps 1e-6 
double cal(double x)
{
    return 42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*pow(x,1);
}//自己设立求导函数 
double sum(double x,double y)
{
    return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-x*y;
}
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        double low=0,high=100,y,mid;
        scanf("%lf",&y);
        while(high-low>eps)
        {//因为是double型所以比较的时候,要考虑精度的问题 
            mid=(high+low)/2;
            if(cal(mid)<y)//这是三分法,呵呵呵 导数小于零,继续因为是凹形 
            low=mid+1e-8;
            else
            high=mid-1e-8;
        }
        printf("%0.4lf\n",sum(mid,y));
    }
    return 0;
}</span>


该链接有关于二分法,三分法的一点小小的体会,不了解的可以去看看

http://blog.csdn.net/ice_alone/article/details/38420043

 

hdu 2899,布布扣,bubuko.com

hdu 2899

原文:http://blog.csdn.net/ice_alone/article/details/38420493

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!