Hdoj 2899.Strange fuction 题解
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 题解的更多相关文章
- hdoj 2899 Strange fuction【二分求解方程】
Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 2899 Strange fuction
http://acm.hdu.edu.cn/showproblem.php?pid=2899 Strange fuction Time Limit: 2000/1000 MS (Java/Others ...
- ACM : HDU 2899 Strange fuction 解题报告 -二分、三分
Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- hdu 2899 Strange fuction (二分法)
Strange fuction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 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 ( ...
- hdu 2899 Strange fuction——模拟退火
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2899 还可三分.不过只写了模拟退火. #include<iostream> #include& ...
- hdu 2899 Strange fuction —— 模拟退火
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2899 模拟退火: 怎么也过不了,竟然是忘了写 lst = tmp ... 还是挺容易A的. 代码如下: # ...
- HDU 2899 Strange fuction 【三分】
三分可以用来求单峰函数的极值. 首先对一个函数要使用三分时,必须确保该函数在范围内是单峰的. 又因为凸函数必定是单峰的. 证明一个函数是凸函数的方法: 所以就变成证明该函数的一阶导数是否单调递增,或者 ...
- hdu 2899 Strange fuction 模拟退火
求 F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)的最小值 模拟退火,每次根据温度随机下个状态,再根据温度转移 #include& ...
随机推荐
- Vue2 实现树形菜单(多级菜单)功能模块
结构示意图 ├── index.html ├── main.js ├── router │ └── index.js # 路由配置文件 ├── components # 组件目录 │ ├── App. ...
- openstack-虚拟化模型
一. 虚拟化模型 1.虚拟化模型 图1 虚拟化模型 图2 KVM架构 2.KVM模块 处理器虚化 内存虚化 3.QEMU设备模型 其它虚化(网卡.声卡.显卡等)
- C++实现算法常用的STL---整理
algorithm min(a,b)和max(a,b) #include<iostream> #include<algorithm> using namespace std; ...
- CodeIgniter框架对数据库查询结果进行统计
假设有一个user表,如果要查询符合条件sex=male的记录数量,有下面几种方法: 方法一:先取回所有符合条件的记录,再count $res = $this->db->query(&qu ...
- 【转】实现Nginx代理WSS协议
https://blog.csdn.net/chopin407/article/details/52937645 后来看到了官网的教程(http://nginx.org/en/docs/http/we ...
- Javascript与C#对变量的处理方式
先来看一下Javascript的情况(下面所说的基本类型和简单类型是一个意思): Javascript中变量会存在两种情况,一种是基本类型的,一共有五种,有null.Bollean.undefin ...
- Docker入门了解一下(第一篇)
最近在学docker.k8s什么的,看得脑子有点乱.从来没弄过在linux上搭建一个分布式的环境,所以对这些不太了解,还是从最简单的地方剖析吧. Docker学习传送:http://www.ityou ...
- day 7-3 僵尸进程,孤儿进程与守护进程
一.基本定义 正常情况下,子进程是通过父进程创建的,子进程在创建新的进程.子进程的结束和父进程的运行是一个异步过程,即父进程永远无法预测子进程 到底什么时候结束. 当一个 进程完成它的工作终止之后,它 ...
- C# Note14: Editable WPF ListView
(1)https://stackoverflow.com/questions/5652527/editable-wpf-listview (2)How to: Create a ListView wi ...
- python数学第三天【方向导数】
1.方向导数 2. 梯度 3. 凸函数: 4. 凸函数的判定 5. 凸函数的一般表示 6. 凸性质的应用