Strange fuction

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

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
 
分析:这个题是要求方程的最小值,首先我们来看一下他的导函数: F’(x) = 42 * x^6+48*x^5+21*x^2+10*x-y(0 <= x <=100)
很显然,导函数是递增的,那么只要求出其导函数的零点就行了,下面就是用二分法求零点!
 
 #include<stdio.h>
#include<math.h>
double hs(double x,double y)
{
return *pow(x,)+*pow(x,)+*pow(x,)+*x*x-y*x;//定义一个求函数值得函数
}
double ds(double x,double y)
{
return *pow(x,)+*pow(x,)+*pow(x,)+*x-y;//定义一个求导数的函数
}
int main()
{
int a;
scanf("%d",&a);
while(a--)
{
double b,x,y,z;
scanf("%lf",&b);
x=0.0;
y=100.0;
do
{
z=(x+y)/;
if(ds(z,b)>)
y=z;
else
x=z;
}while(y-x>1e-);//求出一定精度内导数为0的大约值
printf("%.4lf\n",hs(z,b));
}
return ;
}
 下面是我刚学的三分法:
 
 
 #include<stdio.h>
#include<math.h>
double hs(double x,double y)
{
return *pow(x,)+*pow(x,)+*pow(x,)+*x*x-y*x;
}
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
double l,r,mid,midmid,a;
scanf("%lf",&a);
l=0.0;
r=100.0;
do
{
mid=(l+r)/;
midmid=(mid+r)/;
if(hs(mid,a)>hs(midmid,a))
l=mid;
else
r=midmid;
}while(r-l>1e-);
printf("%.4lf\n",hs(mid,a));
}
return ;
}
 
 

Strange fuction--hdu2899的更多相关文章

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

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

  2. HDU2899 Strange fuction 【二分】

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

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

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

  4. hdu 2899 Strange fuction

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

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

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

  6. Strange fuction

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

  7. hdu 2899 Strange fuction (二分法)

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

  8. Strange fuction hdu 2899

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

  9. hdu2899 Strange fuction

    在区间(0,100).在恒大二阶导数0.f(x)有极小值.用的最低要求的一阶导数值点: #include<math.h> #include<stdio.h> #include& ...

  10. Strange fuction

    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 <=1 ...

随机推荐

  1. XMLHttpRequest基础知识

    XMLHttpRequest 发送请求的两个重要方法:open(method,url,async)——参数:请求方式.请求地址.请求同步/异步:send(string)——参数:使用POST方式时,填 ...

  2. HIBERNATE - 符合Java习惯的关系数据库持久化(精华篇)

    HIBERNATE - 符合Java习惯的关系数据库持久化      下一页 HIBERNATE - 符合Java习惯的关系数据库持久化 Hibernate参考文档 3.0.4   目录 前言 1. ...

  3. CSS3 @font-face 指定英文网页字体

      @font-face是CSS3中的一个模块,他主要是把自己定义的Web字体嵌入到你的网页中,随着@font-face模块的出现,我们在Web的开发中使用字体不怕只能使用Web安全字体.可能有人要问 ...

  4. python随机产生4个互不相等的随机数

    从0-9中随机产生4个互不相等的数, 方法一: import random s=[] while(len(s)<4): x=random.randint(0,9) if x not in s: ...

  5. HDU 1172 猜数字(DFS)

    猜数字 Time Limit:10000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  6. LeetCode_Integer to Roman

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  7. 懒猫们终究要付出代码(本领是一生的),鲸鱼们的短视(逐小利而暴死)——这么说我应该只去互联网公司:IM,云存储,邮箱(别的一概不考虑)

    摘自周鸿伟的书,好像:

  8. Android.mk文件语法规范及使用模板

    Android.mk文件语法详述 介绍:------------这篇文档是用来描述你的C或C++源文件中Android.mk编译文件的语法的,为了理解她们我们需要您先看完docs/OVERVIEW.h ...

  9. EasyMonkeyDevice vs MonkeyDevice&amp;HierarchyViewer API Mapping Matrix

    1. 前言 本来这次文章的title是写成和前几篇类似的<EasyMonkeyDevice API实践全记录>,内容也打算把每一个API的实践和建议给记录下来,但后来想了下认为这样子并非最 ...

  10. Hide a file in a picture

    有时候.假设你想在电脑上隐藏关键的文件而不想让其它人看见.你会怎么做呢?找一个专业的工具?为目录设置password?更改文件属性?这些方法可行.但它们可能不太方便和安全.这里,我给大家共享一个在图片 ...