HDU Strange fuction(二分+精度控制)

相当于y是个常数求 F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)这个函数的最小值,令F‘ = 0,得出x,y的方程,用二分法解方程得x0(易证得x0>=0 && x0<=100),则F‘(x0) = 0,由F‘‘ 在[0-100]上恒大于0,所以F‘在[0-100]上单增,所以F‘(x)<0(x<x0),F‘(x)>0(x>x0),所以F(x)在x=x0处取得最小值,所以本题主要就是二分求解方程的x0,然后直接带入x0,y计算即可。

#include<cstdio>
#include<cmath>
#include<cstdlib>
const double eps = 1e-6;
double cal(double x){
    return 42*pow(x,6.0)+48*pow(x,5.0)+21*pow(x,2.0)+10*x;
}
double gao(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 t;
    double low,high,y,x,res;

    scanf("%d",&t);
    while(t--){
        scanf("%lf",&y);
        low=0.0;
        high=100.0;
        while(high-low>eps){
            x=(low+high)/2;
            res=cal(x);
            if(res<y) {
                low = x + 1e-8;
            }else {
                high = x - 1e-8;
            }
        }
        printf("%0.4lf\n",gao(x,y));
    }
    return 0;
}
时间: 2024-10-24 23:19:49

HDU Strange fuction(二分+精度控制)的相关文章

Hdu 2899 - Strange fuction 二分/三分求函数极值点

Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4527    Accepted Submission(s): 3251 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 <=

HDU 2899 Strange fuction 二分

1.题意:给一个函数F(X)的表达式,求其最值,自变量定义域为0到100 2.分析:写出题面函数的导函数的表达式,二分求导函数的零点,对应的就是极值点 3.代码: 1 # include <iostream> 2 # include <cstdio> 3 # include <cmath> 4 using namespace std; 5 const double eps=1e-8; 6 double Y; 7 int sgn(double x) 8 { 9 if(fa

hdu Strange fuction

本题是一道二分题,但是要利用导数来求最小值.对原函数进行求导,得到的导函数为f(x)=42*pow(x,6)+48*pow(x,5)+21*pow(x,2)+10*x-y;因为0<=x<=100,所以当 y>46802200时,f(x)恒小于0,故F(x)单调递减.当y<46802200时,可知原函数先递减后递增,因此可利用二分找到导函数为零的x的值,再将此x带入原函数就可以得到最小值. #include"iostream" #include"stdi

HDU 5705 Clock (精度控制,暴力)

题意:给定一个开始时间和一个角度,问你下一个时刻时针和分针形成这个角度是几点. 析:反正数量很小,就可以考虑暴力了,从第一秒开始暴力,直到那个角度即可,不会超时的,数目很少,不过要注意精度. 代码如下: #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #inclu

hdu 2899 Strange fuction (二分)

题目链接:http://acm.hdu.edu.cn/showproblem.pihp?pid=2899 题目大意:找出满足F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)的x值.注意精确度的问题. 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 using namespace std; 5 double y; 6 7 doub

ACM : HDU 2899 Strange fuction 解题报告 -二分、三分

Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5933 Accepted Submission(s): 4194 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) C

杭电 HDU ACM Strange fuction

Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4124    Accepted Submission(s): 2964 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 <=

HDU2899 Strange fuction 【二分】

Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2982    Accepted Submission(s): 2202 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 <=

HDU 2899 Strange fuction

Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5253    Accepted Submission(s): 3750 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 <=