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. 每周分享之cookie详解

    本章从JS方向讲解cookie的使用.(实质上后端代码也是差不多用法,无非读取和设置两块) 基本用法:document.cookie="username=pengpeng"; 修改 ...

  2. p201 谱集是闭集 有界集

    1 是如何来的?  由1 如何推出 2 2 是如何来的?谢谢 1.σ是的补集 入属于ρ  稠密是因为   T有定义的地方,λI-T都有定义,有界是因为 所以 然后 ρ是σ的补集 模比||T||大的数都 ...

  3. 迁移 VMware 虚拟机到 KVM

    虚拟机转换| VMware vCenter Converterhttps://www.vmware.com/cn/products/converter.html 迁移 VMware 虚拟机到 KVMh ...

  4. centos ping www.baidu.com ping: unknown host www.baidu.com

    [root@zabbix ~]# cat /etc/resolv.conf ; generated by /sbin/dhclient-script nameserver 219.141.136.10

  5. Java8 flatMap的sample

    外国人写得, 很不错 http://www.java67.com/2016/03/how-to-use-flatmap-in-java-8-stream.html package test; impo ...

  6. edge

    https://www.cnblogs.com/st-leslie/p/6784990.html

  7. 多线程的实现方式01 Thread

    /* * 多线程 有三种实现方式 * 其一 Thread * * 写一个类 * * 1.让他继承 Thread * 2.重写thread中的run方法 * 3.创建子类对象就是在 创建线程! * 3. ...

  8. JavaScript之Json的使用

    Json字符串转JavaScript对象 <html> <body> <h3>通过 JSON 字符串来创建对象</h3> <p> First ...

  9. mysql运行sql文件出错

    从服务器上备份表数据到本地,使用的工具是Navicat,右键表转储sql文件,但是在本地运行sql文件时一直报异常 [Err] 1064 - You have an error in your SQL ...

  10. js写插件教程入门

    原文地址:https://github.com/lianxiaozhuang/blog 转载请注明出处   1. 点击add可以添加个自input的内容到div里并实现变颜色 <div id=& ...