Strange fuction

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

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,求出F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x的最小值,x在0~100之间。

需要先求一下他的导函数42x^6+48x^5+21x^2+10x-y。最小值就是这个导函数为0

这样就可以用二分求一下了,具体看代码

 #include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
double y;
double f(double x)
{
return *x*x*x*x*x*x*x+*x*x*x*x*x*x+*x*x*x+*x*x-y*x;
}
double f2(double x)
{
return *x*x*x*x*x*x+*x*x*x*x*x+*x*x+*x;
}
int main()
{
int t;
while(~scanf("%d",&t))
{
while(t--)
{ scanf("%lf",&y);
double l=0.0,r=100.0,mid=50.0;
while(fabs(f2(mid)-y)>1e-)
{
if(f2(mid)<y)
{
l=mid;
mid=(l+r)/2.0;
}
if(f2(mid)>y)
{
r=mid;
mid=(l+r)/2.0;
} }
printf("%.4lf\n",f(mid));
}
}
return ;
}

最新文章

  1. j2ee之Filter使用实例(页面跳转)
  2. C++-文件【1】-按行读文本文件的两种方法
  3. Thread.Sleep引发ThreadAbortException异常
  4. 解密jQuery内核 DOM操作的核心buildFragment
  5. 用c解决的小题目
  6. [工作中的设计模式]建造者模式builder
  7. 如何优雅的处理Nodejs中的异步回调
  8. ScrollView--嵌套GridView的解决办法
  9. (转)Arcgis API常用接口调用方法
  10. POJ 2226 Muddy Fields (最小点覆盖集,对比POJ 3041)
  11. Laravel 依赖注入原理
  12. js关闭浏览器窗口事件
  13. opencv基础知识------IplImage, CvMat, Mat 的关系和相互转换
  14. Mysql中Insert into xxx on duplicate key update问题
  15. Spring+SpringMVC+MyBatis+easyUI整合优化篇(二)Log4j讲解与整合
  16. 浅谈java类集框架和数据结构(2)
  17. 51Nod P1100 斜率最大
  18. 详解Ajax请求(三)——jQuery对Ajax的实现及serialize()函数对于表单域控件参数提交的使用技巧
  19. Solr 09 - SolrJ操作Solr单机服务 (Solr的Java API)
  20. 面试题:常用的http状态码

热门文章

  1. PHP----练习-----新闻管理----增删改查
  2. poj 1159 Palindrome 【LCS】
  3. BZOJ 1878 [SDOI2009]HH的项链 【莫队】
  4. 搭建一个redis高可用系统
  5. async--ajax异步传输
  6. AD9516锁相环功能外接环路滤波器的设计与分析
  7. 5.同步关键字(synchronized)
  8. LeetCodee 105. Construct Binary Tree from Preorder and Inorder Traversal
  9. oracle 12如何解锁账户锁定状态及修改忘记的密码
  10. 模板——最小生成树prim算法&amp;&amp;向前星理解