您的位置:首页 > 其它

hdu 2899 Strange fuction 三分

2015-09-01 16:44 429 查看


Strange fuction

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 4854 Accepted Submission(s): 3459



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



Recommend

lcy | We have carefully selected several similar problems for you: 2199 2289 2298 2141 3400

求导可知,随参数y值的变化,该函数在定义域内,要么单调递减,要么先递减后递增,故可用三分法求最小值。





double y;
double f(double x)
{
    return 6*pow(x,7)+8*pow(x,6)+7*pow(x,3)+5*pow(x,2)-y*x;
}
double  solve(double le,double ri)
{
    double mid, midmid;
    while(ri-le>0.0000001)
    {
          mid=(le+ri)/2;
          midmid=(mid+ri)/2;
         if(f(mid)<f(midmid) )   ri=midmid;
         else   le=mid;
    }
    return f(mid);
}

int main()
{
    int T;scanf("%d",&T);
    while(T--)
    {
        scanf("%lf",&y);
        printf("%.4lf\n",solve(0.0,100.0) );
    }

    return 0;
}




头文件:

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<climits>
#include<queue>
#include<vector>
#include<map>
#include<sstream>
#include<set>
#include<stack>
#include<utility>
#pragma comment(linker, "/STACK:102400000,102400000")
#define PI 3.1415926535897932384626
#define eps 1e-10
#define sqr(x) ((x)*(x))
#define FOR0(i,n)  for(int i=0 ;i<(n) ;i++)
#define FOR1(i,n)  for(int i=1 ;i<=(n) ;i++)
#define FORD(i,n)  for(int i=(n) ;i>=0 ;i--)
#define  lson   num<<1,le,mid
#define rson    num<<1|1,mid+1,ri
#define MID   int mid=(le+ri)>>1
#define zero(x)((x>0? x:-x)<1e-15)
#define mk    make_pair
#define _f     first
#define _s     second

using namespace std;
const int INF =0x3f3f3f3f;
//const int maxn=    ;
//const int maxm=    ;
//const int INF=    ;
typedef long long ll;
const ll inf =1000000000000000;//1e15;
//ifstream fin("input.txt");
//ofstream fout("output.txt");
//fin.close();
//fout.close();
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
//by yskysker123
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: