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
题意:给你一个y值,x的范围是1~100;求所给方程的最小值;
解题思路:最小值就导数为零的点;
感悟:本来想用二分做,但是。。。。。。不会,后来想起来用导数做;
代码(G++):
#include

#include

using namespace std;

double F(double x,double y)

{

    double
fx;

   
fx=6*x*x*x*x*x*x*x+8*x*x*x*x*x*x+7*x*x*x+5*x*x-x*y;

    return
fx;

}

double f(double x,double y)

{

    double
fx;

   
fx=42*x*x*x*x*x*x+48*x*x*x*x*x+21*x*x+10*x-y;

    return
fx;

}

int main()

{

   
//freopen("in.txt", "r", stdin);

    int n;

    double
y,x1,x2,x;

   
scanf("%d",&n);

    for(int
i=0;i

    {

       
scanf("%lf",&y);

       
x1=0;

       
x2=100;

       
while(true)

       
{

           
x=(x1+x2)/2;

           
if(x2-x1<1e-6)//这里精度最小就得是1e-6

           
{

               
printf("%.4lf\n",F(x,y));

               
break;

           
}

           
else

           
{

               
if(f(x,y)==0)

               
{

                   
printf("%.4lf\n",F(x,y));

                   
break;

               
}

               
else if(f(x,y)<0)

                   
x1=x;

               
else if(f(x,y)>0)

                   
x2=x;

           
}

       
}

    
}

    
return 0;

}

Strange fuction的更多相关文章

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

    Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...

  2. hdu 2899 Strange fuction

    http://acm.hdu.edu.cn/showproblem.php?pid=2899 Strange fuction Time Limit: 2000/1000 MS (Java/Others ...

  3. hdoj 2899 Strange fuction【二分求解方程】

    Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  4. 【精度问题】【HDU2899】Strange fuction

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

  5. Strange fuction

    Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...

  6. hdu 2899 Strange fuction (二分法)

    Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  7. HDU2899 Strange fuction 【二分】

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

  8. Strange fuction hdu 2899

    Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  9. Hdoj 2899.Strange fuction 题解

    Problem Description Now, here is a fuction: F(x) = 6 * x^7+8x^6+7x^3+5x^2-yx (0 <= x <=100) Ca ...

随机推荐

  1. css左右布局的几种实现方式和优缺点

    记录一下左右布局的实现方式,实现的具体效果是,左侧固定宽度,高度适中等于父元素的高度,父元素的高度由右侧内容决定: html代码如下: <div class="parent" ...

  2. AngularJS -- Bootstrap(启动器)

    点击查看AngularJS系列目录 转载请注明出处:http://www.cnblogs.com/leosx/ Bootstrap(初始化) 这章介绍了Angular的初始化过程,以及如何在必要的时候 ...

  3. Maven(六)之依赖管理

    前面讲了maven一些关于Maven的简单知识,今天我给大家分享一些Maven的依赖管理.我相信用过maven的人都知道,它很重要的功能就是通过依赖来添加jar包. 让我们领略一下Maven是怎么管理 ...

  4. CentOSv6.8 修改防火墙配置、修改SSH端口

    查看防火墙目前使用状况: service iptables status 修改防火墙配置: vi /etc/sysconfig/iptables 重启防火墙,让刚才修改的配置生效: service i ...

  5. D. Mysterious Present (看到的一个神奇的DP,也可以说是dfs)

    D. Mysterious Present time limit per test 2 seconds memory limit per test 64 megabytes input standar ...

  6. hdu3065 ac自动机

    病毒侵袭持续中 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  7. hdu3974 找上属的模拟

    There is a company that has N employees(numbered from 1 to N),every employee in the company has a im ...

  8. vscode 调试.net core 2.0 输出乱码解决方法

    之前在vscode上调试.net core 2.0项目时输出窗口一直是乱码,查了很多资料无法解决 最终在github找到了解决办法 ->   https://github.com/OmniSha ...

  9. Linux下安装与配置Nginx

    一.准备 Nginx版本:nginx-1.7.7.tar.gz   请自行到官网下载对应的版本. 二.步骤 ♦在Linux新建一个queenLove用户 [root@localhost /]# use ...

  10. C#.net干货,最全公共帮助类

    比较全面的c#帮助类,日常工作收集,包括前面几家公司用到的,各式各样的几乎都能找到,所有功能性代码都是独立的类,类与类之间没有联系,可以单独引用至项目,分享出来,方便大家,几乎都有注释,喜欢的请点赞, ...