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. SQLSERVER事务日志已满 the transaction log for database 'xx' is full

    解决办法:清除日志 USE [master] GO ALTER DATABASE DNName SET RECOVERY SIMPLE WITH NO_WAIT GO ALTER DATABASE D ...

  2. Python里面如何拷贝一个对象

    1.赋值(=),就是创建了对象的一个新的引用,修改其中任意一个变量都会影响到另一个. In [168]: a Out[168]: [1, 2, 3] In [169]: b=a In [170]: a ...

  3. scrapy框架爬取妹子图片

    首先,建立一个项目#可在github账户下载完整代码:https://github.com/connordb/scrapy-jiandan2 scrapy startproject jiandan2 ...

  4. js去除数组重复成员

    js去除数组重复成员 第一种思路是:遍历要删除的数组arr, 把元素分别放入另一个数组tmp中,在判断该元素在arr中不存在才允许放入tmp中 用到两个函数:for ...in 和 indexOf() ...

  5. 遍历List过程中删除操作报java.util.ConcurrentModificationException错误

    1:遍历List 同时 remove 元素,出现java.util.ConcurrentModificationException错误 @Test public void test3(){ List& ...

  6. 【360图书馆】插入U盘自动攻击:BadUSB原理与实现

    插入U盘自动攻击:BadUSB原理与实现       漏洞背景 “BadUSB”是今年计算机安全领域的热门话题之一,该漏洞由Karsten Nohl和Jakob Lell共同发现,并在今年的Black ...

  7. Redis事物

    redis事物定义: >Redis事务是一个单独的隔离操作:事务中的所有命令都会序列化.按顺序地执行.事务在执行的过程中,不会被其他客户端发送来的命令请求所打断. >Redis事务的主要作 ...

  8. Django--权限信息操作

    一 . 权限控制 表结构的设计 rbca(Role Based Access Control)  基于角色的权限控制 3个model  5张表 class User(models.Model): # ...

  9. Golang的channel使用以及并发同步技巧

    在学习<The Go Programming Language>第八章并发单元的时候还是遭遇了不少问题,和值得总结思考和记录的地方. 做一个类似于unix du命令的工具.但是阉割了一些功 ...

  10. 部署ingress及使用

    一.下载yaml文件 wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.y ...