OpenJudge_P8206 二分法求函数的零点
2015-11-23 19:27
260 查看
总时间限制: 1000ms 内存限制: 65536kB
描述
有函数:
f(x) = x5 - 15 * x4+ 85 * x3- 225 * x2+ 274 * x - 121
已知 f(1.5) > 0 , f(2.4) < 0 且方程 f(x) = 0 在区间 [1.5,2.4] 有且只有一个根,请用二分法求出该根。
输入
无。
输出
该方程在区间[1.5,2.4]中的根。要求四舍五入到小数点后6位。
样例输入
无
样例输出
不提供
多大了一个l在我电脑上输出正确wqnmlgb
描述
有函数:
f(x) = x5 - 15 * x4+ 85 * x3- 225 * x2+ 274 * x - 121
已知 f(1.5) > 0 , f(2.4) < 0 且方程 f(x) = 0 在区间 [1.5,2.4] 有且只有一个根,请用二分法求出该根。
输入
无。
输出
该方程在区间[1.5,2.4]中的根。要求四舍五入到小数点后6位。
样例输入
无
样例输出
不提供
多大了一个l在我电脑上输出正确wqnmlgb
#include<cstdio> #include<iostream> using namespace std; double x,l,r,mid; int k; double f(double x){ double p; p=x*x*x*x*x-15*x*x*x*x+85*x*x*x-225*x*x+274*x-121; return p; } int main(){ l=1.5,r=2.4; while(k<20){ mid=(l+r)/2; x=f(mid); if(x>0) l=mid; else r=mid; k++; } printf("%.6lf",mid); return 0; }
相关文章推荐
- 快速排序里的学问:从猜数字开始
- HDU 4898 The Revenge of the Princess’ Knight ( 2014 Multi-University Training Contest 4 )
- Search Insert Position,Search for a Range,Pow(x, n),Sqrt(x)
- Find Minimum in Rotated Sorted Array II
- [LeetCode] Sqrt(x)
- [LeetCode] Pow(x, n)
- [LeetCode] Search Insert Position
- [LeetCode] Search for a Range
- [LeetCode] Search in Rotated Sorted Array
- openjudge 2739 测试了多组数据结果都是正确的,但是oj提交结果为WA,有人感兴趣的话看看
- PAT 1057 Stack (30)
- int sqrt(int x)
- Pow(x, n)
- Find Minimum in Rotated Sorted Array
- Divide Two Integers
- acm解题报告 HDU 2141 Can you find it?
- acm解题报告 HDU 2199 Can you solve this equation?
- acm解题报告 HDU 2899 Strange fuction
- acm解题报告 HDU 1969 Pie
- acm解题报告 HDU 1061 Rightmost Digit