hdu 2199 Can you solve this equation?(二分法)
2015-08-30 19:29
309 查看
原题链接:
http://acm.hdu.edu.cn/showproblem.php?pid=2199
题目大意:
8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y
给你Y,求x。精确到小数点后四位。
二分法
详见代码:
http://acm.hdu.edu.cn/showproblem.php?pid=2199
题目大意:
8*x^4 + 7*x^3 + 2*x^2 + 3*x + 6 == Y
给你Y,求x。精确到小数点后四位。
二分法
详见代码:
#include<iostream> #include<cmath> using namespace std; double F(double x) { return 8 * x*x*x*x + 7 * x*x*x + 2 * x*x + 3 * x ; } int main() { int T; cin >> T; while (T--) { double n; cin >> n; if (n<6 || n>807020306)// 当0<=x<=100时 , 6<=Y<=807020306 { cout << "No solution!" << endl; continue; } n -= 6;//减去那个常数6,少一丢丢运算量。(也可不省) double left=0, right=100; double mid = 50; while (abs(F(mid) - n)> 0.0001)//二分法 { if (F(mid) > n) { right = mid; mid = (left + right) / 2; } else { left = mid; mid = (left + right) / 2; } } printf("%.4lf\n", mid);//会自动四舍五入 } return 0; }
相关文章推荐
- 面试题8:旋转数组的最小数字
- FZU 2143 Board Game
- <jsp:include page="index.jsp">和<%@include file="index.jsp" %>的区别
- 英特尔首推物联网云平台设备管理
- int * const p 与int const *p或者const int *p的区别
- 空间域二阶统计纹理
- FZU 2141 Sub-Bipartite Graph
- C#——获取本机IP
- 发展物联网云平台将成为互联网时代一场革命
- “支付宝们”会被银行势力给干掉吗?
- 【Python爬虫学习笔记(2)】正则表达式(re模块)相关知识点总结
- FZU 2150 Fire Game
- 自动加载与访问权限
- leetcode[187]Repeated DNA Sequences
- Half year's footsteps
- 004-日期格式器(NSDateFormatter)
- 可行性研究报告——机房收费系统
- Apache RewriteCond %{REQUEST_FILENAME} 不起作用问题
- FZU 2148 Moon Game
- 分享一个递归无限级拼接Json的方法---ExtJs的TreePanel和TreeGrid均适用(Ef,Lambda,Linq,IQueryable,List)