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. 走进Node.js 之 HTTP实现分析

    作者:正龙(沪江Web前端开发工程师) 本文为原创文章,转载请注明作者及出处 上文"走进Node.js启动过程"中我们算是成功入门了.既然Node.js的强项是处理网络请求,那我们 ...

  2. this的四种绑定形式

    一 , this的默认绑定 当一个函数没有明确的调用对象的时候,也就是单纯作为独立函数调用的时候,将对函数的this使用默认绑定:绑定到全局的window对象. 一个例子 function fire ...

  3. java 基础语法 2

    一.语句

  4. oracle pl/sql 分页

    一.无返回值的存储过程 古人云:欲速则不达,为了让大家伙比较容易接受分页过程编写,我还是从简单到复杂,循序渐进的给大家讲解.首先是掌握最简单的存储过程,无返回值的存储过程. 案例:现有一张表book, ...

  5. [Node.js] 2、利用node-git-server快速搭建git服务器

    本文用到了node-git-server 1.检测本地git版本 该包的使用需要机器上本来就安装git,且git的版本大于等于2.7: ╭─root@lt /home/workspace ╰─# gi ...

  6. 为ASP.NetCore程序启用SSL

    紧接着上一篇搭建连接MySql的三层架构的ASP.NetCore2.0的WebApi的案例,这篇来实现为ASP.NetCore启用SSL支持 由于ASP.NetCore默认服务器Kestrel不像ii ...

  7. express 安装和运行

    1.npm install -g express-generator 2.进入服务目录(自己定义的文件夹,或者express Myapp && cd Myapp 新建Myapp文件夹并 ...

  8. hdu1671字典树

    Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. php过滤textarea 中的换行符问题

    之前我写的替换代码是这样的 $content = str_replace('\r\n', '', $_POST['content']); 为了确保window和Linux的换行符都能去掉,改成这样的: ...

  10. 从 JavaScript 到 TypeScript 系列

    随着应用的庞大,项目中 JavaScript 的代码也会越来越臃肿,这时候许多 JavaScript 的语言弊端就会愈发明显,而 TypeScript 的出现,就是着力于解决 JavaScript 语 ...