Problem Description

Now, here is a fuction:

F(x) = 6 * x7+8*x6+7x3+5*x2-yx (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

Author

Redow


思路

函数是:\(F(x) = 6x^7+8x^6+7x^3+5x^2-yx\)

导函数是:\(F'(x) = 42x^6 +48x^5+21x^2+10x-y\)

由题目条件可得,导函数单调递增,\(F'(100)\)最大,如果它还小于0,说明原函数单调递减,\(F(100)\)最小。其他情况是:二分查找导函数的零点,找到后代入原函数就可以得到答案

代码

#include<bits/stdc++.h>
using namespace std; double y;
double f(double x)
{
return 6*pow(x,7) + 8*pow(x,6) + 7*pow(x,3) + 5*pow(x,2) - y*x;
}//函数 double df(double x)
{
return 42*pow(x,6) + 48*pow(x,5) + 21*pow(x,2) + 10*x - y;
}//导函数
int main()
{
int n;
cin >> n;
while(n--)
{
cin >> y;
if(df(100) <= 0)
{
printf("%.4lf\n",f(100));
continue;
}
double l = 0, r = 100.0;
double mid;
while(r-l>=1e-8)
{
mid = (l+r)/2;
if(df(mid)<0)
l = mid;
else
r = mid;
}
printf("%.4lf\n",f(mid));
}
return 0;
}

Hdoj 2899.Strange fuction 题解的更多相关文章

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

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

  2. hdu 2899 Strange fuction

    http://acm.hdu.edu.cn/showproblem.php?pid=2899 Strange fuction Time Limit: 2000/1000 MS (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 (二分法)

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

  5. 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 ( ...

  6. hdu 2899 Strange fuction——模拟退火

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2899 还可三分.不过只写了模拟退火. #include<iostream> #include& ...

  7. hdu 2899 Strange fuction —— 模拟退火

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2899 模拟退火: 怎么也过不了,竟然是忘了写 lst = tmp ... 还是挺容易A的. 代码如下: # ...

  8. HDU 2899 Strange fuction 【三分】

    三分可以用来求单峰函数的极值. 首先对一个函数要使用三分时,必须确保该函数在范围内是单峰的. 又因为凸函数必定是单峰的. 证明一个函数是凸函数的方法: 所以就变成证明该函数的一阶导数是否单调递增,或者 ...

  9. hdu 2899 Strange fuction 模拟退火

    求  F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)的最小值 模拟退火,每次根据温度随机下个状态,再根据温度转移 #include& ...

随机推荐

  1. 【学习总结】Git学习-参考廖雪峰老师教程二-安装Git

    学习总结之Git学习-总 目录: 一.Git简介 二.安装Git 三.创建版本库 四.时光机穿梭 五.远程仓库 六.分支管理 七.标签管理 八.使用GitHub 九.使用码云 十.自定义Git 期末总 ...

  2. 虚拟机Ubuntu图形界面进入命令行快捷键

    ctrl+alt+f2 https://jingyan.baidu.com/article/03b2f78c69e5c25ea337ae40.html https://www.zabbix.com/d ...

  3. jdk环境变量配置注意事项

    cmd 运行java -version 显示错误 Registry key 'Software\JavaSoft\Java Runtime Environment\CurrentVersion'has ...

  4. 高阶组件 HOC

    一. A higher-order component (HOC) is an advanced technique in React for reusing component logic. a h ...

  5. IdentityServer4【Topic】之保护APIs

    Protecting APIs 保护api 默认情况下IdentityServer将access token发布成JWT(json web token)格式的. 现在,每个相关的平台都支持验证JWT令 ...

  6. Eclipse的DEgub调试乱跳

    去掉勾选,是软件的BUG

  7. eclipse 部署项目

  8. spring 给一个类 生成test

    右击一个类,然后:GoTo==>test ,就可以新建这个类的测试用例了,简单粗暴, 如果想要不污染数据库,就在一个测试用例 的标签@Test 下面在加上@RollBack 这样: @Test ...

  9. how to build an app with github

    how to build an app with github Building apps https://developer.github.com/apps/ demos https://githu ...

  10. Best Chrome Extensions

    Best Chrome Extensions chrome://extensions/ # ghelper chrome-extension://cieikaeocafmceoapfogpffaalk ...