练习2- Strange fuction
2016-04-24 21:32
169 查看
题目:
[align=left]Problem Description[/align]Now, here is a fuction:<br> F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=100)<br>Can you find the minimum value when x is between 0 and 100.
[align=left]Input[/align]
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)
[align=left]Output[/align]
Just the minimum value (accurate up to 4 decimal places),when x is between 0 and 100.
[align=left]Sample Input[/align]
2<br>100<br>200
[align=left]Sample Output[/align]
-74.4291<br>-178.8534
[align=left]Author[/align]
Redow
题意:
解方程;思路:
解方程,对方程进行求导,然后跟第一题做法一样,求出x;代码:
# include <iostream> # include <cmath> # include <iomanip> using namespace std; double f (double x, double y) { return 6 * pow(x, 7) + 8 * pow(x, 6) + 7 * pow(x, 3)+ 5 * x * x - y * x; } double ff (double x) { return 42 * pow(x, 6) + 48 * pow(x, 5) + 21 * x * x + 10 * x ; } int main() { int n; cin >> n; while (n--) { double min = 0, max = 100, x; int y; cin >> y; while (1) { x = (min + max) / 2; if (fabs(ff(x) - y) < 1e-4) { cout << fixed << setprecision(4) << f (x, y) << endl; break; } else if (ff(x) > y) { max = x; } else { min = x; } } } return 0; } //42 * pow(x, 6) + 48 * pow(x, 5) + 10 * x - y;
相关文章推荐
- 推荐书单---目前的藏书
- 剑指offer:二叉树中和为某一值的路径
- Mysql利用mysql_multi配置一台主机多个实例(转)
- Java大牛养成记(5)——The content of element type "struts" must match "(package|include|bean|constant)*".
- listview嵌套listview,子listview只显示一个item问题
- mysql启动和关闭外键约束的方法
- LightOJ 1364 Expected Cards (概率DP)
- 剑指offer之面试题18:树的子结构
- 1019 N皇后问题
- c#高效的线程安全队列ConcurrentQueue<T>(上)
- Unity UGUI 图片 轴对称效果 减少资源
- 烧钱下的分享经济分享的是投资人经济?
- 监听器图库
- 【SSH】Spring简介和应用
- 安卓开发之java基础篇笔记【1】
- &&和||的优先级
- 介绍NSURLSESSION网络请求套件
- 《极简笔记》源码分析(二)
- Sping MVC Token防止表单重复提交
- String、StringBuffer与StringBuilder之间区别